From 5d8ce59a2578d7c145c33461727aed6391aa22bf Mon Sep 17 00:00:00 2001 From: Arash Deshmeh Date: Mon, 26 Feb 2018 15:23:52 -0500 Subject: [PATCH] fix the error message in Substitute function Signed-off-by: Arash Deshmeh --- cli/compose/template/template.go | 10 +++++++--- cli/compose/template/template_test.go | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cli/compose/template/template.go b/cli/compose/template/template.go index 2792a09ba5..086194b8fe 100644 --- a/cli/compose/template/template.go +++ b/cli/compose/template/template.go @@ -7,7 +7,7 @@ import ( ) var delimiter = "\\$" -var substitution = "[_a-z][_a-z0-9]*(?::?[-?][^}]+)?" +var substitution = "[_a-z][_a-z0-9]*(?::?[-?][^}]*)?" var patternString = fmt.Sprintf( "%s(?i:(?P%s)|(?P%s)|{(?P%s)}|(?P))", @@ -75,7 +75,9 @@ func Substitute(template string, mapping Mapping) (string, error) { name, errorMessage := partition(substitution, ":?") value, ok := mapping(name) if !ok || value == "" { - err = &InvalidTemplateError{Template: errorMessage} + err = &InvalidTemplateError{ + Template: fmt.Sprintf("required variable %s is missing a value: %s", name, errorMessage), + } return "" } return value @@ -84,7 +86,9 @@ func Substitute(template string, mapping Mapping) (string, error) { name, errorMessage := partition(substitution, "?") value, ok := mapping(name) if !ok { - err = &InvalidTemplateError{Template: errorMessage} + err = &InvalidTemplateError{ + Template: fmt.Sprintf("required variable %s is missing a value: %s", name, errorMessage), + } return "" } return value diff --git a/cli/compose/template/template_test.go b/cli/compose/template/template_test.go index 66e50124ed..4fec57e8e8 100644 --- a/cli/compose/template/template_test.go +++ b/cli/compose/template/template_test.go @@ -97,23 +97,23 @@ func TestMandatoryVariableErrors(t *testing.T) { }{ { template: "not ok ${UNSET_VAR:?Mandatory Variable Unset}", - expectedError: "Mandatory Variable Unset", + expectedError: "required variable UNSET_VAR is missing a value: Mandatory Variable Unset", }, { template: "not ok ${BAR:?Mandatory Variable Empty}", - expectedError: "Mandatory Variable Empty", + expectedError: "required variable BAR is missing a value: Mandatory Variable Empty", }, { template: "not ok ${UNSET_VAR:?}", - expectedError: "", + expectedError: "required variable UNSET_VAR is missing a value", }, { - template: "not ok ${UNSET_VAR?Mandatory Variable Unset", - expectedError: "Mandatory Variable Unset", + template: "not ok ${UNSET_VAR?Mandatory Variable Unset}", + expectedError: "required variable UNSET_VAR is missing a value: Mandatory Variable Unset", }, { template: "not ok ${UNSET_VAR?}", - expectedError: "", + expectedError: "required variable UNSET_VAR is missing a value", }, }