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

refactor: all exits moved to cli, throw as needed #157

Merged
merged 1 commit into from Jun 23, 2021

Conversation

drazisil-codecov
Copy link
Contributor

This makes the main() method testable.

@drazisil-codecov drazisil-codecov requested a review from a team as a code owner June 22, 2021 15:11
@drazisil-codecov
Copy link
Contributor Author

@RA80533 I would love your review here as well. :)

drazisil-codecov referenced this pull request Jun 22, 2021
* fix: correct headers

Fixes #145
@codecov
Copy link

codecov bot commented Jun 22, 2021

Codecov Report

Merging #157 (8318991) into master (cffff17) will increase coverage by 0.60%.
The diff coverage is 67.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #157      +/-   ##
==========================================
+ Coverage   91.57%   92.17%   +0.60%     
==========================================
  Files          15       15              
  Lines         546      537       -9     
  Branches      105      101       -4     
==========================================
- Hits          500      495       -5     
+ Misses         20       16       -4     
  Partials       26       26              
Flag Coverage Δ
alpine 92.17% <67.21%> (+0.60%) ⬆️
linux 92.17% <67.21%> (+0.60%) ⬆️
linux-without-git ∅ <ø> (∅)
macos 92.17% <67.21%> (+0.60%) ⬆️
macos-without-git ∅ <ø> (∅)
windows 91.62% <67.21%> (+0.59%) ⬆️
windows-without-git ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/index.js 75.30% <67.21%> (+1.97%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cffff17...8318991. Read the comment docs.

@drazisil-codecov drazisil-codecov merged commit 69e3064 into master Jun 23, 2021
@drazisil-codecov drazisil-codecov deleted the refactor-exit branch June 23, 2021 13:26
@drazisil-codecov
Copy link
Contributor Author

@RA80533 this is now merged, so refactoring globs / io will likely be a lot easier.

drazisil-codecov added a commit that referenced this pull request Jun 23, 2021
* chore(deps): update dependency eslint to v7.29.0 (#150)
* chore(deps): update alpine docker tag to v3.14.0 (#144)
* chore(deps): update dependency jest to v27.0.5 (#156)
* fix: correct flags regex to match server and docs (#147)
* refactor: all exits moved to cli, throw as needed (#157)
* chore: change headers to standard (#158)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Drazi Crendraven <drazisil@users.noreply.github.com>
Comment on lines +109 to +117
app.main(argv).then(() => {
const end = Date.now()
app.log(`End of uploader: ${end - start} milliseconds`, { level: 'debug', argv })
}).catch(error => {
app.log(`Error!: ${error}`, { level: 'error', argv })
const end = Date.now()
app.log(`End of uploader: ${end - start} milliseconds`, { level: 'debug', argv })
process.exit(argv.nonZero ? -1 : 0)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea here is perfect.

The finally() method can be used here in the same manner as the traditional try-catch-finally construct:

try {
  somethingThatWillThrowAnError();
} catch (reason) {
  handleTheError(reason);
} finally {
  // Close out any file handles, etc.
  performAnyCleanUpToTheEnvironment();
}
app.main(argv).catch(error => { /* … */ }).finally(() => { /* … */ });
Suggested change
app.main(argv).then(() => {
const end = Date.now()
app.log(`End of uploader: ${end - start} milliseconds`, { level: 'debug', argv })
}).catch(error => {
app.log(`Error!: ${error}`, { level: 'error', argv })
const end = Date.now()
app.log(`End of uploader: ${end - start} milliseconds`, { level: 'debug', argv })
process.exit(argv.nonZero ? -1 : 0)
})
app.main(argv).catch(error => {
app.log(`Error!: ${error}`, { level: 'error', argv })
process.exitCode = argv.nonZero ? -1 : 0
}).finally(() => {
const end = Date.now()
app.log(`End of uploader: ${end - start} milliseconds`, { level: 'debug', argv })
})
})

Copy link
Contributor

Choose a reason for hiding this comment

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

One thing to keep in mind is that setting the exitCode property of process will not cause the program to immediately terminate. Node.js will run its course throughout whatever execution flow it's currently running but the program will terminate with the assigned exit code. This is more often the appropriate pattern to use (instead of process.exit(), etc.).

The official documentation (here) has more information pertaining to how Node.js terminates.

@RA80533
Copy link
Contributor

RA80533 commented Jun 23, 2021

I meant to push my review comments as I made them rather than bundle them together into a review. I'm not sure if these comments were visible prior to the merge.

@drazisil-codecov
Copy link
Contributor Author

I meant to push my review comments as I made them rather than bundle them together into a review. I'm not sure if these comments were visible prior to the merge.

Nope, but that's good to know about the exitCode. Normally I would want to quit on the spot , but in this case since I duplicate code, your suggestions makes more sense.

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.

None yet

3 participants