Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 7, 2026

Addresses potential nil pointer panic when cli.RunCommandWithStdIn fails to start. The function returns nil result on startup failure, but the code unconditionally dereferenced result.Stdout and result.Stderr.

Changes:

  • Add nil check before accessing result fields
  • Split error handling: err != nil case (uses -1 exit code when result is nil) and defensive result.ExitCode != 0 case
  • Fix incorrect doc comment on executeAzdCommandWithExec

Before:

result, err := cli.RunCommandWithStdIn(ctx, "", args...)
output := result.Stdout + result.Stderr  // panic if result is nil
if err != nil || result.ExitCode != 0 {
    // both conditions checked in single block
}

After:

result, err := cli.RunCommandWithStdIn(ctx, "", args...)

var output string
if result != nil {
    output = result.Stdout + result.Stderr
}

if err != nil {
    var exitCode int = -1  // command failed to start
    if result != nil {
        exitCode = result.ExitCode
    }
    // handle error
}

if result != nil && result.ExitCode != 0 {
    // defensive check for non-zero exit without error
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits January 7, 2026 21:47
Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on integration tests for AI Agents Extension Fix nil pointer dereference in executeAzdCommand test utility Jan 7, 2026
Copilot AI requested a review from trangevi January 7, 2026 21:58
@trangevi trangevi closed this Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants