-
Notifications
You must be signed in to change notification settings - Fork 744
Implementing error codes and adding the errorCode() function #269
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
Conversation
|
I've modified some of the calls to Because the default error code is |
src/common.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be _code != 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote it like this for two reasons:
- This prefers non-default return codes. If a command has two errors (and
fatal=== false, so it doesn't exit yet), and one is a non-default return code, then it prefers that value overall (which probably tells the user more useful information). - This gives the user a way to send warning messages (output like an error, but don't change the status code) by providing
_code === 0
I thought about changing it to if (state.errorCode === 0 || state.errorCode === DEFAULT_RETURN_CODE) instead, but that would allow error('...', 0) to wipe out a previous non-zero code, which it probably shouldn't do.
What do you think?
|
Looks Great, Just a few minor things I pointed out, and two bigger ones too:
Otherwise, looks great! |
|
Thanks for the feedback! I responded inline to the minor comments. In response to the major comments:
Also, what do you think about camel case for We might also consider adding a |
|
@ariporad I updated this and rebased off master. I reverted most of the calls to If it looks good, feel free to merge. If not, leave some comments and I'll address them. |
|
@ariporad I think this is ready for review now |
|
@nfisher: Sorry for the delay. I still think that we should just make And we should defiantly use cammelCase. What do we use now? |
|
Right now everything is lower case. "tempdir" is an example. I agree that works well for exec (and is more intuitive), but I think someone may still want this feature for a non-exec function. Maybe we name this to error() and rename that to errorMsg()? Or we refactor things heavily so that every command returns an object that has a stderr field. I'm working right now to have each command return objects instead of simple strings (which should allow for pipes), and could add the stderr field. This isn't my preferred method though, since I think relying on error messages is fairly fragile (especially since we just fixed bugs related to error messages) |
|
@nfischer: I think that we should wait till me and you and @arturadib (If he wants) to get together in gitter. It kind of revolves around how much we want to mess with shellljs. (I personally want to do a large refactor, and to standardize everything. Then we can just to a breaking change). |
|
👍 |
|
Rebased off master |
Implement error codes internally. The script will exit with the status of the last command. The default code for errors is 1.
|
@nfischer: Since we're not meeting with Artur, I think we should just refactor everything to return an object with .stderr/.stdout, and have |
|
My only concern is that it would break a lot of backwards compatibility. I agree it's a cleaner API, but do you think enough people are relying on the old behavior? I can do that refactor either way, though 👍 |
|
@nfischer: Hmm... My comment didn't go through. I meant to say (like 4 days ago) that I think breaking changes were invented for a reason. |
|
Hmm ok. It'll take me a couple days to sort out the bugs I ran into from the |
|
@nfischer: What's the status on this? Also, could you rebase off master? |
|
@ariporad still in progress. I can rebase off master, but I think you'd prefer a different interface to expose return codes, so I'm waiting until I make some other changes. I'd at least like a stderr field being returned before we get rid of the current functionality of error() |
|
@nfischer: bump. |
|
@ariporad I think we should wait until #360 is merged, and then revisit alternate implementations. The way I see it it is that we can either do:
|
|
Yup. I was working on it a bit yesterday. It's been a busy week, but I should have something out by Friday. I'll open this as a new PR. |
|
I'm working on refactoring this today. I should have this out by tonight in a new PR. |
|
Bump, this PR is tagged as blocking 1st release of shx. Anything I can do to help? |
|
I'll wrap this up later this week, just a little in over my head right now. @levithomason could you investigate a fix for how shelljs commands (that have fatal errors) don't output to the console sometimes? the issue was introduced when we converted |
|
Sure thing, I'll review this issue and see what I can find. |
|
@levithomason I'll try to make a bug report that more clearly documents the problem. And I'll get out a primitive implementation of error codes today (finally got some spare time). |
|
Sounds good, I pulled this branch and perused around but needed more context. Will wait to hear back from you. |
|
@levithomason the bug isn't in this branch. This branch is pretty ancient at this point (I'm refactoring everything in a new branch). I'll ping you in the bug report, and describe it better there. |
|
I'm closing this, since #394 is a better replacement |
This implements error codes for the builtin commands. Each command will now have an associated error code (
common.status.code). I changed many of the commands to return the code that the corresponding Linux command would return (ex.ls('asdfasdf')returns 2).This fixes a bug with
exec()as well. Previously, you would see the following results:Any non-zero exit code means that
error()will return a truthy value.If
config.fatalis set, then the process will exit with the last return code that was set, emulating Bash's behavior.This adds the
errorCode()function to access the last error code, which is somewhat of a substitute for Bash's$?variable. This is good if a command's output may vary, but its return codes can be relied upon to stay consistent (or if output is inconvenient to type). It can be used like so: