[go: nahoru, domu]

Skip to content

Commit

Permalink
internal/command: wrap formatted errors (opentofu#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrs committed Sep 21, 2023
1 parent 487d9bc commit a257fc9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion internal/command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ func (m *Meta) checkRequiredVersion() tfdiags.Diagnostics {

pwd, err := os.Getwd()
if err != nil {
diags = diags.Append(fmt.Errorf("Error getting pwd: %s", err))
diags = diags.Append(fmt.Errorf("Error getting pwd: %w", err))
return diags
}

Expand Down
4 changes: 2 additions & 2 deletions internal/command/meta_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (m *Meta) installModules(ctx context.Context, rootDir, testsDir string, upg

err := os.MkdirAll(m.modulesDir(), os.ModePerm)
if err != nil {
diags = diags.Append(fmt.Errorf("failed to create local modules directory: %s", err))
diags = diags.Append(fmt.Errorf("failed to create local modules directory: %w", err))
return true, diags
}

Expand Down Expand Up @@ -294,7 +294,7 @@ func (m *Meta) inputForSchema(given cty.Value, schema *configschema.Block) (cty.
val := cty.StringVal(strVal)
val, err = convert.Convert(val, attrS.Type)
if err != nil {
m.showDiagnostics(fmt.Errorf("Invalid value: %s", err))
m.showDiagnostics(fmt.Errorf("Invalid value: %w", err))
continue
}

Expand Down
4 changes: 2 additions & 2 deletions internal/command/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func (c *OutputCommand) Outputs(statePath string) (map[string]*states.OutputValu

env, err := c.Workspace()
if err != nil {
diags = diags.Append(fmt.Errorf("Error selecting workspace: %s", err))
diags = diags.Append(fmt.Errorf("Error selecting workspace: %w", err))
return nil, diags
}

// Get the state
stateStore, err := b.StateMgr(env)
if err != nil {
diags = diags.Append(fmt.Errorf("Failed to load state: %s", err))
diags = diags.Append(fmt.Errorf("Failed to load state: %w", err))
return nil, diags
}

Expand Down
2 changes: 1 addition & 1 deletion internal/command/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *PlanCommand) OperationRequest(
var err error
opReq.ConfigLoader, err = c.initConfigLoader()
if err != nil {
diags = diags.Append(fmt.Errorf("Failed to initialize config loader: %s", err))
diags = diags.Append(fmt.Errorf("Failed to initialize config loader: %w", err))
return nil, diags
}

Expand Down
2 changes: 1 addition & 1 deletion internal/command/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (c *RefreshCommand) OperationRequest(be backend.Enhanced, view views.Refres
var err error
opReq.ConfigLoader, err = c.initConfigLoader()
if err != nil {
diags = diags.Append(fmt.Errorf("Failed to initialize config loader: %s", err))
diags = diags.Append(fmt.Errorf("Failed to initialize config loader: %w", err))
return nil, diags
}

Expand Down
4 changes: 2 additions & 2 deletions internal/command/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *ShowCommand) Run(rawArgs []string) int {
// Check for user-supplied plugin path
var err error
if c.pluginPath, err = c.loadPluginPath(); err != nil {
diags = diags.Append(fmt.Errorf("error loading plugin path: %s", err))
diags = diags.Append(fmt.Errorf("error loading plugin path: %w", err))
view.Diagnostics(diags)
return 1
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func (c *ShowCommand) showFromLatestStateSnapshot() (*statefile.File, tfdiags.Di
// Load the workspace
workspace, err := c.Workspace()
if err != nil {
diags = diags.Append(fmt.Errorf("error selecting workspace: %s", err))
diags = diags.Append(fmt.Errorf("error selecting workspace: %w", err))
return nil, diags
}

Expand Down
4 changes: 2 additions & 2 deletions internal/command/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func (c *ValidateCommand) Run(rawArgs []string) int {

dir, err := filepath.Abs(args.Path)
if err != nil {
diags = diags.Append(fmt.Errorf("unable to locate module: %s", err))
diags = diags.Append(fmt.Errorf("unable to locate module: %w", err))
return view.Results(diags)
}

// Check for user-supplied plugin path
if c.pluginPath, err = c.loadPluginPath(); err != nil {
diags = diags.Append(fmt.Errorf("error loading plugin path: %s", err))
diags = diags.Append(fmt.Errorf("error loading plugin path: %w", err))
return view.Results(diags)
}

Expand Down

0 comments on commit a257fc9

Please sign in to comment.