Skip to content

Commit 3e39a53

Browse files
committed
fix: Fixing some govet findings
1 parent c315fbf commit 3e39a53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1220
-1095
lines changed

cli/app.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ func initialSetup(cliCtx *cli.Context, opts *options.TerragruntOptions) error {
286286

287287
opts.RootWorkingDir = filepath.ToSlash(workingDir)
288288

289-
if err := opts.Logger.Formatter().SetBaseDir(opts.RootWorkingDir); err != nil {
289+
err = opts.Logger.Formatter().SetBaseDir(opts.RootWorkingDir)
290+
if err != nil {
290291
return err
291292
}
292293

cli/commands/catalog/tui/tui.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313

1414
func Run(ctx context.Context, modules module.Modules, opts *options.TerragruntOptions) error {
1515
if _, err := tea.NewProgram(newModel(modules, opts), tea.WithAltScreen(), tea.WithContext(ctx)).Run(); err != nil {
16-
if err := context.Cause(ctx); errors.Is(err, context.Canceled) {
16+
if causeErr := context.Cause(ctx); errors.Is(causeErr, context.Canceled) {
1717
return nil
18-
} else if err != nil {
19-
return err
18+
} else if causeErr != nil {
19+
return causeErr
2020
}
2121

2222
return err

cli/commands/catalog/tui/update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ func updatePager(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
8686

8787
switch msg := msg.(type) {
8888
case tea.KeyMsg:
89-
bb, cmd := m.buttonBar.Update(msg)
89+
bb, updateCmd := m.buttonBar.Update(msg)
9090
m.buttonBar = bb.(*buttonbar.ButtonBar)
9191

92-
if cmd != nil {
93-
cmds = append(cmds, cmd)
92+
if updateCmd != nil {
93+
cmds = append(cmds, updateCmd)
9494
}
9595

9696
switch {

cli/commands/common/graph/action.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func Run(ctx context.Context, opts *options.TerragruntOptions) error {
2828
// if destroy-graph-root is empty, use git to find top level dir.
2929
// may cause issues if in the same repo exist unrelated modules which will generate errors when scanning.
3030
if rootDir == "" {
31-
gitRoot, err := shell.GitTopLevelDir(ctx, opts, opts.WorkingDir)
32-
if err != nil {
33-
return err
31+
gitRoot, gitRootErr := shell.GitTopLevelDir(ctx, opts, opts.WorkingDir)
32+
if gitRootErr != nil {
33+
return gitRootErr
3434
}
3535

3636
rootDir = gitRoot

cli/commands/common/graph/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func WrapCommand(opts *options.TerragruntOptions, cmd *cli.Command) *cli.Command
5656
}
5757

5858
opts.RunTerragrunt = func(ctx context.Context, opts *options.TerragruntOptions) error {
59-
cliCtx := cliCtx.WithValue(options.ContextKey, opts)
60-
return action(cliCtx)
59+
cliCtxWithValue := cliCtx.WithValue(options.ContextKey, opts)
60+
return action(cliCtxWithValue)
6161
}
6262

6363
return Run(cliCtx, opts.OptionsFromContext(cliCtx))

cli/commands/common/runall/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func WrapCommand(opts *options.TerragruntOptions, cmd *cli.Command) *cli.Command
6767
}
6868

6969
opts.RunTerragrunt = func(ctx context.Context, opts *options.TerragruntOptions) error {
70-
cliCtx := cliCtx.WithValue(options.ContextKey, opts)
71-
return action(cliCtx)
70+
cliCtxWithValue := cliCtx.WithValue(options.ContextKey, opts)
71+
return action(cliCtxWithValue)
7272
}
7373

7474
return Run(cliCtx, opts.OptionsFromContext(cliCtx))

cli/commands/exec/action.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ func Run(ctx context.Context, opts *options.TerragruntOptions, cmdOpts *Options,
2727
func runTargetCommand(cmdOpts *Options, args cli.Args) run.TargetCallbackType {
2828
return func(ctx context.Context, opts *options.TerragruntOptions, cfg *config.TerragruntConfig) error {
2929
var (
30-
command = args.CommandName()
31-
args = args.Tail()
32-
dir = opts.WorkingDir
30+
command = args.CommandName()
31+
tailArgs = args.Tail()
32+
dir = opts.WorkingDir
3333
)
3434

3535
if !cmdOpts.InDownloadDir {
3636
dir = opts.RootWorkingDir
3737
}
3838

3939
return run.RunActionWithHooks(ctx, command, opts, cfg, func(ctx context.Context) error {
40-
_, err := shell.RunCommandWithOutput(ctx, opts, dir, false, false, command, args...)
40+
_, err := shell.RunCommandWithOutput(ctx, opts, dir, false, false, command, tailArgs...)
4141
if err != nil {
4242
return errors.Errorf("failed to run command in directory %s: %w", dir, err)
4343
}

cli/commands/find/action.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ func Run(ctx context.Context, opts *Options) error {
3737
case SortAlpha:
3838
cfgs = cfgs.Sort()
3939
case SortDAG:
40-
q, err := queue.NewQueue(cfgs)
41-
if err != nil {
42-
return errors.New(err)
40+
q, queueErr := queue.NewQueue(cfgs)
41+
if queueErr != nil {
42+
return errors.New(queueErr)
4343
}
4444

4545
cfgs = q.Entries()

cli/commands/graph/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ func action(opts *options.TerragruntOptions) cli.ActionFunc {
3939
return func(cliCtx *cli.Context) error {
4040
opts.RunTerragrunt = func(ctx context.Context, opts *options.TerragruntOptions) error {
4141
if cmd := cliCtx.Command.Subcommand(opts.TerraformCommand); cmd != nil {
42-
cliCtx := cliCtx.WithValue(options.ContextKey, opts)
42+
cliCtxWithValue := cliCtx.WithValue(options.ContextKey, opts)
4343

44-
return cmd.Action(cliCtx)
44+
return cmd.Action(cliCtxWithValue)
4545
}
4646

4747
return run.Run(ctx, opts)

cli/commands/hclfmt/action.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ func bytesDiff(opts *options.TerragruntOptions, b1, b2 []byte, path string) ([]b
216216
}
217217

218218
defer func() {
219-
if err := f1.Close(); err != nil {
220-
opts.Logger.Warnf("Failed to close file %s %v", f1.Name(), err)
219+
if closeErr := f1.Close(); closeErr != nil {
220+
opts.Logger.Warnf("Failed to close file %s %v", f1.Name(), closeErr)
221221
}
222222

223-
if err := os.Remove(f1.Name()); err != nil {
224-
opts.Logger.Warnf("Failed to remove file %s %v", f1.Name(), err)
223+
if removeErr := os.Remove(f1.Name()); removeErr != nil {
224+
opts.Logger.Warnf("Failed to remove file %s %v", f1.Name(), removeErr)
225225
}
226226
}()
227227

@@ -231,21 +231,21 @@ func bytesDiff(opts *options.TerragruntOptions, b1, b2 []byte, path string) ([]b
231231
}
232232

233233
defer func() {
234-
if err := f2.Close(); err != nil {
235-
opts.Logger.Warnf("Failed to close file %s %v", f2.Name(), err)
234+
if closeErr := f2.Close(); closeErr != nil {
235+
opts.Logger.Warnf("Failed to close file %s %v", f2.Name(), closeErr)
236236
}
237237

238-
if err := os.Remove(f2.Name()); err != nil {
239-
opts.Logger.Warnf("Failed to remove file %s %v", f2.Name(), err)
238+
if removeErr := os.Remove(f2.Name()); removeErr != nil {
239+
opts.Logger.Warnf("Failed to remove file %s %v", f2.Name(), removeErr)
240240
}
241241
}()
242242

243-
if _, err := f1.Write(b1); err != nil {
244-
return nil, err
243+
if _, f1WriteErr := f1.Write(b1); f1WriteErr != nil {
244+
return nil, f1WriteErr
245245
}
246246

247-
if _, err := f2.Write(b2); err != nil {
248-
return nil, err
247+
if _, f2WriteErr := f2.Write(b2); f2WriteErr != nil {
248+
return nil, f2WriteErr
249249
}
250250

251251
data, err := exec.Command("diff", "--label="+filepath.Join("old", path), "--label="+filepath.Join("new/", path), "-u", f1.Name(), f2.Name()).CombinedOutput()

0 commit comments

Comments
 (0)