Skip to content

[rayapp] updating rayapp to handle errors correctly#490

Merged
elliot-barn merged 2 commits into
mainfrom
elliot-barn-update-rayapp-test-stderr-handling
May 14, 2026
Merged

[rayapp] updating rayapp to handle errors correctly#490
elliot-barn merged 2 commits into
mainfrom
elliot-barn-update-rayapp-test-stderr-handling

Conversation

@elliot-barn

@elliot-barn elliot-barn commented May 12, 2026

Copy link
Copy Markdown
Collaborator

Problem

The anyscale CLI sometimes exits with code 0 even when a remote run_command
has failed. In those cases it logs the failure via logrus to stderr, e.g.:

time="2026-05-04T19:45:34Z" level=fatal msg="exec failed with exit code 1"

Previously, runAnyscaleCLI in rayapp/anyscale_cli.go only scanned stdout
for the exec failed with exit code marker when the exit code was 0, so these
failures were silently treated as success. (Non-zero exits were already handled
and did include stderr in the error message — the gap was specifically the
exit-0-with-stderr-marker case.)

Changes

rayapp/anyscale_cli.go

  • Capture stderr into a local variable unconditionally (alongside stdout)
    after cmd.Run().
  • Extend the post-success check to scan both stdout and stderr for
    "exec failed with exit code".
  • When that marker is found, include both streams in the returned error
    for full diagnostic context.

rayapp/anyscale_cli_test.go

  • Rename the existing stdout-marker case to "exec failed with exit code in stdout".
  • Add a new case "exec failed with exit code in stderr" that simulates the
    logrus-style stderr output (level=fatal msg="exec failed with exit code 1")
    with exit code 0, and asserts the error is still surfaced.

Uncaught failure: https://buildkite.com/anyscale/template-probe/builds/42/canvas?jid=019e1cb4-1046-4ee7-a113-790ea651edbf&tab=output#019e1cb4-1046-4ee7-a113-790ea651edbf/L712

Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
…ot-barn-update-rayapp-test-stderr-handling
@elliot-barn elliot-barn requested a review from sai-miduthuri May 12, 2026 22:33

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Anyscale CLI wrapper to correctly detect remote command failures that log 'exec failed with exit code' to stderr while exiting with a zero status code. It ensures both stdout and stderr are captured and included in the error message. Additionally, a new test case was added to verify this behavior for stderr. The reviewer suggested using a constant for the failure message string to improve maintainability and making the error message more descriptive.

Comment thread rayapp/anyscale_cli.go
Comment on lines +70 to 76
if strings.Contains(stdout, "exec failed with exit code") ||
strings.Contains(stderr, "exec failed with exit code") {
return "", fmt.Errorf(
"anyscale error: command failed:\nstdout: %s\nstderr: %s",
stdout, stderr,
)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The error message "command failed:" is somewhat generic. Since this block specifically handles a known CLI issue where it exits with 0 despite a remote failure, using a constant for the error string and including it in the error message improves both maintainability and error clarity for the user.

Suggested change
if strings.Contains(stdout, "exec failed with exit code") ||
strings.Contains(stderr, "exec failed with exit code") {
return "", fmt.Errorf(
"anyscale error: command failed:\nstdout: %s\nstderr: %s",
stdout, stderr,
)
}
const failureMsg = "exec failed with exit code"
if strings.Contains(stdout, failureMsg) ||
strings.Contains(stderr, failureMsg) {
return "", fmt.Errorf(
"anyscale error: %s detected:\nstdout: %s\nstderr: %s",
failureMsg, stdout, stderr,
)
}

@elliot-barn elliot-barn marked this pull request as ready for review May 12, 2026 23:25
@elliot-barn elliot-barn merged commit 2d74798 into main May 14, 2026
5 checks passed
@elliot-barn elliot-barn deleted the elliot-barn-update-rayapp-test-stderr-handling branch May 14, 2026 00:24
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