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.
This commit is contained in:
Martin Atkins 2017-10-04 17:15:23 -07:00
parent 61cd3bf02a
commit fc20f419dd
2 changed files with 4 additions and 5 deletions

View File

@ -47,7 +47,7 @@ func (m *Meta) Module(path string) (*module.Tree, error) {
err = mod.Load(m.moduleStorage(m.DataDir()), module.GetModeNone) err = mod.Load(m.moduleStorage(m.DataDir()), module.GetModeNone)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error loading modules: %s", err) return nil, errwrap.Wrapf("Error loading modules: {{err}}", err)
} }
return mod, nil return mod, nil

View File

@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"github.com/hashicorp/errwrap"
) )
// configurable is an interface that must be implemented by any configuration // 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) { func (t *importTree) ConfigTree() (*configTree, error) {
config, err := t.Raw.Config() config, err := t.Raw.Config()
if err != nil { if err != nil {
return nil, fmt.Errorf( return nil, errwrap.Wrapf(fmt.Sprintf("Error loading %s: {{err}}", t.Path), err)
"Error loading %s: %s",
t.Path,
err)
} }
// Build our result // Build our result