Skip to content

fix: include error values in init_step_runner log messages#6382

Open
kuishou68 wants to merge 1 commit intorunatlantis:mainfrom
kuishou68:fix/issue-6381-init-step-runner-missing-error-in-log
Open

fix: include error values in init_step_runner log messages#6382
kuishou68 wants to merge 1 commit intorunatlantis:mainfrom
kuishou68:fix/issue-6381-init-step-runner-missing-error-in-log

Conversation

@kuishou68
Copy link
Copy Markdown

Closes #6381

Problem

In server/core/runtime/init_step_runner.go, two error conditions log a message but silently drop the actual error values from the format string arguments:

  1. When common.IsFileTracked returns an error, the log call is:

    ctx.Log.Warn("Error checking if %s is tracked in %s", lockFileName, path)
    //                                                      ^^^ err is captured but never logged!
  2. When utils.RemoveIgnoreNonExistent returns an error, the log call is:

    ctx.Log.Info("Error Deleting `%s`", lockFileName)
    //                                     ^^^ delErr is captured but never logged!

This means operators see a vague log message with no information about the root cause of the failure.

Fix

  • Add the missing error variable err to the first log call's format args
  • Add the missing error variable delErr to the second log call's format args
  • Promote the second log from Info to Warn since it represents an error condition
// Before
ctx.Log.Warn("Error checking if %s is tracked in %s", lockFileName, path)
ctx.Log.Info("Error Deleting `%s`", lockFileName)

// After
ctx.Log.Warn("Error checking if %s is tracked in %s: %s", lockFileName, path, err)
ctx.Log.Warn("Error Deleting `%s`: %s", lockFileName, delErr)

Copilot AI review requested due to automatic review settings April 10, 2026 01:53
@dosubot dosubot bot added bug Something isn't working go Pull requests that update Go code labels Apr 10, 2026
@github-actions github-actions bot removed the bug Something isn't working label Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves operational diagnosability of InitStepRunner by ensuring logged error conditions include the underlying error values (and by raising one log to Warn) so failures around .terraform.lock.hcl handling are actionable in production.

Changes:

  • Include err in the “is file tracked” warning log message.
  • Promote the lockfile deletion failure log from Info to Warn and include delErr in the message.
Comments suppressed due to low confidence (1)

server/core/runtime/init_step_runner.go:33

  • When common.IsFileTracked returns an error, terraformLockFileTracked will be false (see IsFileTracked implementation), so the subsequent if common.FileExists(...) && !terraformLockFileTracked may delete .terraform.lock.hcl even though tracking status is unknown. Consider guarding the deletion with err == nil (or otherwise defaulting to “tracked” on error) to avoid potentially deleting a git-tracked lockfile when git ls-files fails.
	terraformLockfilePath := filepath.Join(path, lockFileName)
	terraformLockFileTracked, err := common.IsFileTracked(path, lockFileName)
	if err != nil {
		ctx.Log.Warn("Error checking if %s is tracked in %s: %s", lockFileName, path, err)
	}
	// If .terraform.lock.hcl is not tracked in git and it exists prior to init
	// delete it as it probably has been created by a previous run of
	// terraform init
	if common.FileExists(terraformLockfilePath) && !terraformLockFileTracked {

@kuishou68 kuishou68 force-pushed the fix/issue-6381-init-step-runner-missing-error-in-log branch from 9a7251f to e240f7a Compare April 10, 2026 11:08
Guard lock file deletion when IsFileTracked returns an error to prevent
silent error swallowing in log output.

Closes runatlantis#6381

Signed-off-by: Cocoon-Break <54054995+kuishou68@users.noreply.github.com>
@kuishou68 kuishou68 force-pushed the fix/issue-6381-init-step-runner-missing-error-in-log branch from e240f7a to f90f05e Compare April 10, 2026 11:13
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update Go code lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: init_step_runner.go swallows errors in log messages (error values missing from format args)

3 participants