actions / actions/toolkit

Non-zero `exitCode` is not accessible from `exec`/`getExecOutput` with `ignoreReturnCode: false`

Open
#1,615 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
5.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Describe the enhancement
When ignoreReturnCode: false is set and a process exits with a non-zero exit code, an Error is thrown. This error contains the message The process '${this.toolPath}' failed with exit code ${this.processExitCode} but has no direct access to the exit code and would need to be parsed from the message as a workaround.

Compare this to ignoreReturnCode: true, which has the exitCode readily accessible.


let { exitCode, stdout, stderr } = await exec.getExecOutput(
  'ls', ['package.json'], 
  {ignoreReturnCode: true}
)

Code Snippet

try {
  // Non-zero exits will proceed to `catch`
  let { exitCode, stdout, stderr } = await exec.getExecOutput(
    'ls', ['package.json'], 
    {ignoreReturnCode: false}
  )
} catch (error) {
   // Exit code is not accessible in `error.exitCode`
}

Additional information
Related code: https://github.com/actions/toolkit/blob/main/packages/exec/src/toolrunner.ts#L530-L534

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at packages/exec/src/toolrunner.ts around lines 530-534 and compare the error path with the ignoreReturnCode: true result. Make the non-zero exit code available directly on the caught error, then verify that callers no longer need to parse it from the message.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
2/5
Estimated time
Half a day
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.