From fc20f419dd38eceb82aec6f315f5779f5cfef8ef Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 4 Oct 2017 17:15:23 -0700 Subject: [PATCH] config and command: use errwrap to propagate config load errors Previously we were using fmt.Sprintf and thus forcing the stringification of the wrapped error. Using errwrap allows us to unpack the original error at the top of the stack, which is useful when the wrapped error is really a hcl.Diagnostics containing potentially-multiple errors and possibly warnings. --- command/meta_new.go | 2 +- config/import_tree.go | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/command/meta_new.go b/command/meta_new.go index a1d376b34..9447caf3b 100644 --- a/command/meta_new.go +++ b/command/meta_new.go @@ -47,7 +47,7 @@ func (m *Meta) Module(path string) (*module.Tree, error) { err = mod.Load(m.moduleStorage(m.DataDir()), module.GetModeNone) if err != nil { - return nil, fmt.Errorf("Error loading modules: %s", err) + return nil, errwrap.Wrapf("Error loading modules: {{err}}", err) } return mod, nil diff --git a/config/import_tree.go b/config/import_tree.go index 3c0912dd9..08cbc7736 100644 --- a/config/import_tree.go +++ b/config/import_tree.go @@ -5,6 +5,8 @@ import ( "fmt" "io" "os" + + "github.com/hashicorp/errwrap" ) // configurable is an interface that must be implemented by any configuration @@ -125,10 +127,7 @@ func (t *importTree) Close() error { func (t *importTree) ConfigTree() (*configTree, error) { config, err := t.Raw.Config() if err != nil { - return nil, fmt.Errorf( - "Error loading %s: %s", - t.Path, - err) + return nil, errwrap.Wrapf(fmt.Sprintf("Error loading %s: {{err}}", t.Path), err) } // Build our result