-
Notifications
You must be signed in to change notification settings - Fork 61
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
Do not call sprintf with one argument #63
Comments
Thanks for submitting this! I really don't like the change in behavior regarding format specifiers like '%s' in a single-argument string. Similar ideas have been discussed extensively in #57, #8, and a few others. In particular, this question and the reply under it. I get that this is a rough edge, and I'm sorry for the pain it causes, but I find the alternative painful, too (inconsistent behavior regarding cases that are otherwise the same from a user's perspective). #57 proposes an alternate constructor that would avoid this particular rough edge for people who want that. I think that's the way to go here. |
As an example, I think it's pretty confusing that |
@davepacheco thanks for the feedback, I picked up the work from #57 with adding the modifications you asked in the CL: https://cr.joyent.us/#/c/4394 New CL: https://cr.joyent.us/#/c/5360/ Please review. |
Will this be done soon? |
@gabegorelick I did provide feedback on the change back in January but I believe the author went a different route. I just tried to pick it up myself and apply the feedback but there's a little more work left than I realized. The new change is here: https://cr.joyent.us/#/c/6608/ The main difference from review 5360 is that I've refactored the code as I suggested in 5360. I think this is the best starting point if somebody wants to pick up the test suite work. I'm not sure when I'll get to that again. |
Portions contributed by: David Pacheco <[email protected]>
My history of verror work that led to the
My current intent:
|
This commit bases CordovaError on the popular joyent/node-verror. We actually use @netflix/nerror, a VError fork for now. That's because we do not want printf style error formatting support and that forks allows to disable it. There's [ongoing work][1] to integrate that change into the original VError. So basically CordovaError behaves like PError but with all the static methods from VError and different parameter ordering for its constructor. One change that could break some existing tests in repositories that use cordova-common is that `toString` (for errors without a cause argument) now behaves like the Error default again: new CordovaError('foo').toString(); // old result: 'foo' // new result: 'CordovaError: foo' [1]: TritonDataCenter/node-verror#63 (comment)
This commit bases CordovaError on the popular [joyent/node-verror]. We actually use @netflix/nerror, a VError fork, for now. That's because we do not want printf style error formatting support and that fork allows to disable it. There's [ongoing work][1] to integrate that change into the original VError. So basically CordovaError behaves like PError but with all the static methods from VError and different parameter ordering for its constructor. One change that could break some existing tests in repositories that use cordova-common is that `toString` (for errors without a cause argument) now behaves like the Error default again: new CordovaError('foo').toString(); // old result: 'foo' // new result: 'CordovaError: foo' [joyent/node-verror]: https://github.com/joyent/node-verror [1]: TritonDataCenter/node-verror#63 (comment)
This commit bases CordovaError on the popular [joyent/node-verror]. We actually use @netflix/nerror, a VError fork, for now. That's because we do not want printf style error formatting support and that fork allows to disable it. There's [ongoing work][1] to integrate that change into the original VError. So basically CordovaError behaves like PError but with all the static methods from VError and different parameter ordering for its constructor. One change that could break some existing tests in repositories that use cordova-common is that `toString` (for errors without a cause argument) now behaves like the Error default again: new CordovaError('foo').toString(); // old result: 'foo' // new result: 'CordovaError: foo' [joyent/node-verror]: https://github.com/joyent/node-verror [1]: TritonDataCenter/node-verror#63 (comment)
This commit bases CordovaError on the popular [joyent/node-verror]. We actually use @netflix/nerror, a VError fork, for now. That's because we do not want printf style error formatting support and that fork allows to disable it. There's [ongoing work][1] to integrate that change into the original VError. So basically CordovaError behaves like PError but with all the static methods from VError and different parameter ordering for its constructor. One change that could break some existing tests in repositories that use cordova-common is that `toString` (for errors without a cause argument) now behaves like the Error default again: new CordovaError('foo').toString(); // old result: 'foo' // new result: 'CordovaError: foo' [joyent/node-verror]: https://github.com/joyent/node-verror [1]: TritonDataCenter/node-verror#63 (comment)
This commit bases CordovaError on the popular [joyent/node-verror]. We actually use @netflix/nerror, a VError fork, for now. That's because we do not want printf style error formatting support and that fork allows to disable it. There's [ongoing work][1] to integrate that change into the original VError. So basically CordovaError behaves like PError but with all the static methods from VError and different parameter ordering for its constructor. One change that could break some existing tests in repositories that use cordova-common is that `toString` (for errors without a cause argument) now behaves like the Error default again: new CordovaError('foo').toString(); // old result: 'foo' // new result: 'CordovaError: foo' [joyent/node-verror]: https://github.com/joyent/node-verror [1]: TritonDataCenter/node-verror#63 (comment)
This commit bases CordovaError on the popular [joyent/node-verror]. We actually use @netflix/nerror, a VError fork, for now. That's because we do not want printf style error formatting support and that fork allows to disable it. There's [ongoing work][1] to integrate that change into the original VError. So basically CordovaError behaves like PError but with all the static methods from VError and different parameter ordering for its constructor. One change that could break some existing tests in repositories that use cordova-common is that `toString` (for errors without a cause argument) now behaves like the Error default again: new CordovaError('foo').toString(); // old result: 'foo' // new result: 'CordovaError: foo' [joyent/node-verror]: https://github.com/joyent/node-verror [1]: TritonDataCenter/node-verror#63 (comment)
This commit bases CordovaError on the popular [joyent/node-verror]. We actually use @netflix/nerror, a VError fork, for now. That's because we do not want printf style error formatting support and that fork allows to disable it. There's [ongoing work][1] to integrate that change into the original VError. So basically CordovaError behaves like PError but with all the static methods from VError and different parameter ordering for its constructor. One change that could break some existing tests in repositories that use cordova-common is that `toString` (for errors without a cause argument) now behaves like the Error default again: new CordovaError('foo').toString(); // old result: 'foo' // new result: 'CordovaError: foo' [joyent/node-verror]: https://github.com/joyent/node-verror [1]: TritonDataCenter/node-verror#63 (comment)
This commit bases CordovaError on the popular [joyent/node-verror]. We actually use @netflix/nerror, a VError fork, for now. That's because we do not want printf style error formatting support and that fork allows to disable it. There's [ongoing work][1] to integrate that change into the original VError. So basically CordovaError behaves like PError but with all the static methods from VError and different parameter ordering for its constructor. One change that could break some existing tests in repositories that use cordova-common is that `toString` (for errors without a cause argument) now behaves like the Error default again: new CordovaError('foo').toString(); // old result: 'foo' // new result: 'CordovaError: foo' [joyent/node-verror]: https://github.com/joyent/node-verror [1]: TritonDataCenter/node-verror#63 (comment)
PR https://cr.joyent.us/#/c/5299
Safe user inputs in messages
Addresses the issue when someone builds message manually and it contains user-input with formatting characters instead of using
sprintf
.For example:
In this case VError throws without this change:
Related to #57
Performance Improvement
Calling
sprintf
is expensive, do not call when zero arguments are passed.In some scenarios, an application needs to create hundreds of VError(s).
To test the change's effect:
On my 2017 MBP 3.5Ghz, I see a 27% performance improvement after the change.
Before:
The text was updated successfully, but these errors were encountered: