Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,42 @@ func executeAzdCommand(ctx context.Context, cli *azdcli.CLI, testSuite *Integrat

cli.WorkingDirectory = testSuite.AzdProjectDir
result, err := cli.RunCommandWithStdIn(ctx, "", args...)
output := result.Stdout + result.Stderr

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

LogCommandOutput(strings.Join(args, " "), []byte(output))

if err != nil || result.ExitCode != 0 {
Logf("Command failed with error: %v, exit code: %d", err, result.ExitCode)
if err != nil {
var exitCode int = -1 // Default to -1 when result is nil (command failed to start)
if result != nil {
exitCode = result.ExitCode
}
Logf("Command failed with error: %v, exit code: %d", err, exitCode)
return "", &InitError{
Message: output,
Err: fmt.Errorf("exit code %d: %w", exitCode, err),
}
}

// Defensive check: handle case where err is nil but exit code is non-zero
// This shouldn't normally happen based on RunCommandWithStdIn implementation,
// but we check defensively in case the implementation changes
if result != nil && result.ExitCode != 0 {
Logf("Command failed with exit code: %d", result.ExitCode)
return "", &InitError{
Message: output,
Err: fmt.Errorf("exit code %d: %w", result.ExitCode, err),
Err: fmt.Errorf("exit code %d", result.ExitCode),
}
}
Logf("Command completed successfully")

return output, nil
}

// executeAzdCommand executes an azd command and returns output and agent version if available
// executeAzdCommandWithExec executes an azd command using exec.Command and returns the output
func executeAzdCommandWithExec(ctx context.Context, testSuite *IntegrationTestSuite, timeout time.Duration, args []string) (string, error) {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
Expand Down