diff --git a/envplate.go b/envplate.go index 7848600..1352599 100644 --- a/envplate.go +++ b/envplate.go @@ -117,6 +117,10 @@ func (h *Handler) parse(file string) error { }) + if len(errors) > 0 { + return errors[0] + } + if h.DryRun { Log(DEBUG, "Expanding all references in '%s' without doing anything (dry-run)", file) Log(RAW, parsed) @@ -144,10 +148,6 @@ func (h *Handler) parse(file string) error { } - if len(errors) > 0 { - return errors[0] - } - return nil } diff --git a/envplate_test.go b/envplate_test.go index c9fbd47..15b08b3 100644 --- a/envplate_test.go +++ b/envplate_test.go @@ -229,11 +229,30 @@ func TestStrictParse(t *testing.T) { file = "test/template4.txt" ) - defer _restore(file) - err := handler.parse(file) assert.Error(err) assert.Equal("'test/template4.txt' requires undeclared environment variable 'ANOTHER_DATABASE', but cannot use default 'db2.example.com' (strict-mode)", err.Error()) } + +func TestAbortOnParseErrors(t *testing.T) { + + assert := assert.New(t) + handler := &Handler{ + Backup: true, + Strict: true, + } + + var ( + file = "test/template4.txt" + template = _read(t, file) + ) + + err := handler.parse(file) + assert.Error(err) + + assert.Equal(template, _read(t, file)) + assert.NoFileExists(fmt.Sprintf("%s.bak", file)) + +}