Repository navigation
Conversation
5 of 7 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose / Goal
Fixes #894.
The built-in CLI crashed with an uncaught exception when the input file was missing or the
-ooutput file couldn't be written. Thetry/catchinsrc/cli/cli.jswas meant to printSeems an invalid file or stream., but thethrow errcalls run inside async callbacks (fs.readFile,fs.writeFile,ReadToEnd.readToEnd). Those run after thetryblock has already returned, so thecatchnever sees them.Input
Actual output (before): uncaught
ENOENT, with a stack trace pointing atthrow err;(cli.js:80).Expected output (after)
The exit code is 1.
Changes
onErrorhelper and return, instead of throwing. The helper prints the existing message and setsprocess.exitCode = 1. The existingcatchuses the same helper, so it now also exits non-zero.spec/cli_spec.jswith one positive case (parse from stdin) and two negative cases (missing input file, unwritable-opath). Both negative cases fail before this change and pass after it.I reproduced the missing-file and unwritable-output cases. I couldn't trigger the stdin stream-error path from the shell, but it had the same
throw-in-callback shape, so it gets the same handling.Testing
npm test: 335 specs, 0 failures.npm run test-types: passes.src/cli/cli.js, which the parser and builder don't import, sobenchmark/XmlParser.mjsandbenchmark/XmlBuilder.mjsare unaffected.Type