Skip to content

feat: return CLI exit codes for remote functions#6025

Merged
marcindobry merged 10 commits into
masterfrom
marcin/NAN-5373-have-the-cli-return-error-codes-instead-of-always-success
May 15, 2026
Merged

feat: return CLI exit codes for remote functions#6025
marcindobry merged 10 commits into
masterfrom
marcin/NAN-5373-have-the-cli-return-error-codes-instead-of-always-success

Conversation

@marcindobry
Copy link
Copy Markdown
Contributor

Adds explicit CLI exit codes for compile, dryrun, and deploy failures so remote-functions can classify E2B/Docker command failures from exit codes instead of output regexes. Dryrun service methods now return Result values, and remote/local dryrun and deploy clients use CLI exit-code mapping while preserving stdout-only success parsing.

NAN-5373

  • npm run test:unit -- packages/cli/lib/utils.unit.test.ts packages/cli/lib/services/dryrun.service.unit.test.ts packages/cli/lib/services/sdk.service.unit.test.ts packages/server/lib/services/remote-function/command-output.unit.test.ts packages/server/lib/services/remote-function/cli-exit-codes.unit.test.ts packages/server/lib/services/remote-function/dryrun-client.unit.test.ts packages/server/lib/services/remote-function/deploy-client.unit.test.ts
  • npm run ts-build

@linear
Copy link
Copy Markdown

linear Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 17 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 28b323f7c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

throw new RemoteFunctionError({ code: 'dryrun_error', message: dryrunErrorOutput, status: 400 });
}

return { output: getDryrunCommandSuccessOutput({ stdout: result.stdout, stderr: result.stderr }) };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve zero-exit dryrun error detection

This now treats every nango dryrun exit-0 result as success, but our sandbox runtime can run a CLI build that still reports dryrun failures only in stderr while exiting 0 (the removed fallback explicitly handled this compatibility case). In that rollout window, failed dryruns will be returned as successful output instead of dryrun_error, which can produce false-positive test/preview results for users. Please keep a stderr/content-based fallback (or gate this on verified CLI version) until all runtimes are guaranteed to emit the new non-zero exit codes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is experimental API, some breakage during deployment is fine.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50bb5b1b95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +34 to +38
switch (getCommandExitCode(error)) {
case NANGO_CLI_COMPILE_ERROR_EXIT_CODE:
return 'compilation_error';
case NANGO_CLI_DEPLOY_ERROR_EXIT_CODE:
default:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep compile fallback when deploy exits with unknown code

getDeployErrorCode now defaults every non-10 exit to deployment_error, so a deploy compile failure from a runtime that still exits with generic code 1 will be mislabeled even when the output clearly contains typecheck errors. Before this change, invokeDeploy/invokeLocalDeploy used output-based detection as a compatibility fallback; removing it regresses error classification during mixed CLI-runtime rollouts and can send users down the wrong remediation path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/cli/lib/index.ts">

<violation number="1" location="packages/cli/lib/index.ts:417">
P1: Avoid `process.exit(...)` here; it can truncate pending stdout/stderr output. Set `process.exitCode` and return so output flushes before exit.</violation>

<violation number="2" location="packages/cli/lib/index.ts:419">
P1: Do not force `process.exit(0)` on success; it can cut off stdout output needed by callers. Return naturally (or set `process.exitCode = 0` then return).</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic.

Comment thread packages/cli/lib/index.ts Outdated
Comment thread packages/cli/lib/index.ts Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1b02bc7b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/server/lib/services/remote-function/cli-exit-codes.ts
@superagent-security superagent-security Bot added the contributor:verified Contributor passed trust analysis. label May 14, 2026
@marcindobry marcindobry requested review from a team and kaposke May 14, 2026 12:35
import type { FunctionErrorCode } from '@nangohq/types';

// Keep in sync with packages/cli/lib/exit-codes.ts.
export const NangoCliExitCode = {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find a good place to put this so that it's shared between the CLI and the server so I'm keeping it duplicated for now. Candidate packages were:

  • shared - this isn't really "shared" between all packages but mostly backend packages
  • utils - this isn't published so it would require publishing it or bundling the whole thing into the CLI. It has a lot of heavy stuff inside so not worth it for 3 constants.
  • types - these are runtime constants, not types, so not a good fit
  • server - Don't want to import all of server inside the CLI
  • runner-sdk - The best existing candidate since the CLI already imports it, but the error codes are used by the server and cli, not runner-sdk

An alternative would be a new package but I don't think it's worth it for 3 constants.

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.

Always a bit of a pain. I think we need to create an actually shared package eventually. Webapp as the same problem requiring duplication

@marcindobry marcindobry added this pull request to the merge queue May 15, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 15, 2026
@marcindobry marcindobry force-pushed the marcin/NAN-5373-have-the-cli-return-error-codes-instead-of-always-success branch from 1746fd8 to 86ab5dd Compare May 15, 2026 11:07
@marcindobry marcindobry added this pull request to the merge queue May 15, 2026
Merged via the queue into master with commit fffcc1d May 15, 2026
26 checks passed
@marcindobry marcindobry deleted the marcin/NAN-5373-have-the-cli-return-error-codes-instead-of-always-success branch May 15, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:verified Contributor passed trust analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants