-
Notifications
You must be signed in to change notification settings - Fork 89
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: Error handling #284
Conversation
a76fd84
to
407c4d1
Compare
@aarondill think we should close this one? |
why's that? |
Perhaps it needs to be rebased/refactored. I'm struggling to see what it adds on top of #281 |
Stops any successful output. Errors are still outputted.
This commit creates stdout and stderr functions for outputting with respect to isQuiet and adds support for differing (easier to parse) messages if not connected to a TTY (eg. a pipe or process substitution) Additionally changes the 'No matching files.' message to output on stderr rather than on stdout as it was, which makes sense because this output represents erroneous usage.
these variables can be set to force output on the specified chanel as if it were connected to a terminal. macro.testCLI can now take an argument of the following form: isTerminal: { stderr: false, stdout: false },
The exit code is now the number of files which failed when sorting. On a successful run, this will be 0 and exit w/ success, but if any errors occur, this will be incremented. In check mode, this is fails + unsorted.
Wraps fs calls in trycatch to not throw and to count failures. Also better messages and script usage
91bcf47
to
ea61369
Compare
👎 For increasing complex. Can't get why we need these changes. |
Even if we want a better error message, we can just try/catch those possible errors and print a friendly message. |
I have rebased this onto keithamus/master and removed extra changes to make the diff slightly clearer. The history is a bit of a mess, I could clean it up if you'd like, but I figure it'll get squashed in the merge anyways. This builds on 281 by improving the developer experience when using the CLI in shell scripts. You can read the changes in the new section of the readme, but it boils down to this:
|
This does increase complexity, but it allows for much easier scripting, without difficult parsing. which is especially difficult if all messages are outputted to stdout. |
Don't mind untidy history, as long as the diff+description makes up for it 😉. I see where you're going with this, and I don't mind improving the output for scripts, but I think we can perhaps improve error messaging in general. Let's first get better error messages in the general case, then let's work to figure out a way to make error messages more parseable. TTY detection is a bit too much magic for my preference. |
I'd like to do a refactor. |
That seems like a good idea |
@aarondill c5dd2cc WDYT? |
It looks good. To clarify, this doesn’t affect any of the output, correct? I didn’t see any changes in the snapshot |
also, this seems slightly overly verbose: isCheck
? `${status.failedFilesCount} files could not be checked.`
: `${status.failedFilesCount} files could not be sorted.`, perhaps this could be simplified to `${status.failedFilesCount} files could not be ${isCheck ? 'checked' : 'sorted'}.` potentially on the next line as well. This is entirely stylistic though, and may be better in its current state if we ever plan to change these output statements |
Not changed.
That's why I wrote like this. |
Here comes the actual message change. b22d474 Good? |
Perhaps use template strings, rather than the console.log format strings( |
The message change itself looks good |
We can still use |
I extracted reporter to a separate file, you can just add changes to that file if you still want do the TTY thing, but I suggest we should keep things simple. |
For now, lets keep it simple, especially since @keithamus has said they prefer it that way |
@aarondill We need update https://github.com/keithamus/sort-package-json#usage, since output changed. |
🎉 This PR is included in version 2.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I notice that you merged this PR. would you like me to create a new PR or just continue to commit this change here? |
This already merged, you can send a new one. |
This PR refactors the code to enclose common error points in try catch blocks and outputting the message property on the error to the user on stderr. This further allows tolerant errors where the program is not halted, but instead continues to process other files.