Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: shell.errorCode() honors shell.exit(code) #1122

Merged
merged 1 commit into from
Jul 16, 2023
Merged

Conversation

nfischer
Copy link
Member

This changes shell.exit() to use a wrapper function. This is so that shell.errorCode() will have the correct error code after invoking shell.exit(code). This isn't normally relevant, however a caller may be listening for the exit status:

process.on('exit', code => {
  shell.exit(shell.errorCode());
});

Issue #1013

@nfischer nfischer added the bash compat Compatibility issues with bash or POSIX behavior label Jun 26, 2023
@nfischer nfischer added this to the v0.9.0 milestone Jun 26, 2023
This changes shell.exit() to use a wrapper function. This is so that
shell.errorCode() will have the correct error code after invoking
shell.exit(code). This isn't normally relevant, however a caller may be
listening for the exit status:

```
process.on('exit', code => {
  shell.exit(shell.errorCode());
});
```

Issue #1013
@codecov-commenter
Copy link

codecov-commenter commented Jun 26, 2023

Codecov Report

Patch coverage: 20.00% and project coverage change: -0.29 ⚠️

Comparison is base (a3a7e74) 97.19% compared to head (34aa58f) 96.90%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1122      +/-   ##
==========================================
- Coverage   97.19%   96.90%   -0.29%     
==========================================
  Files          36       36              
  Lines        1354     1358       +4     
==========================================
  Hits         1316     1316              
- Misses         38       42       +4     
Impacted Files Coverage Δ
shell.js 69.23% <20.00%> (-30.77%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@nfischer
Copy link
Member Author

Also fixed shell.exit() to update shell.error() with a truthy value, which means you could also write code like this:

process.on('exit', code => {
  shell.exit(shell.error() ? 1 : 0);
});

@nfischer nfischer merged commit f7a7c75 into master Jul 16, 2023
66 checks passed
@nfischer nfischer deleted the feat-exit-errorcode branch July 16, 2023 04:32
nfischer added a commit that referenced this pull request Nov 12, 2023
This adds test coverage for the shell.exit() function. This also
refactors how we mock stdout/stderr and adds support for mocking
process.exit() (which was needed for this change).

While I was writing these tests, I realized there was an edge case I
missed in PR #1122. This change fixes that edge case.

Issue #1013
nfischer added a commit that referenced this pull request Nov 12, 2023
This adds test coverage for the shell.exit() function. This also
refactors how we mock stdout/stderr and adds support for mocking
process.exit() (which was needed for this change).

While I was writing these tests, I realized there was an edge case I
missed in PR #1122. This change fixes that edge case.

Issue #1013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bash compat Compatibility issues with bash or POSIX behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants