mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
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:
parent
61cd3bf02a
commit
fc20f419dd
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user