-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Add multiple error reporting #192
Add multiple error reporting #192
Conversation
This change will need a lot more tests. |
@sindresorhus I think these tests should cover almost everything that is needed! Of course, however, if you have any other edge cases you may want me to test, please let me know! 😋 I tried to cover every code path possible, and, as coverages report, all are covered |
I merged master into this PR, let me know if there's anything you'd like changed 🙏 |
Per the original issue. The error is meant for humans, so it should present all the errors by default. |
Sorry for the slow reply. I'm just finally now getting through my long list of notifications. |
Don't worry, I would've assumed that was the case! It's totally understandable |
There we go @sindresorhus, the errors outputted are now in one big message, while also keeping the
|
Seems like the code coverage is below the threshold. |
Local Coverage report
|
d5ff153
to
bb3be97
Compare
src: throw error on any predicate only if there are any chore: make default message empty Doesn't matter much as it's overwritten immediately after chore: drop redundant nullish coalescing fix: declare the validationErrors prop as readonly Gives a TS compilation error if you try to reassign it chore: generate error message only if there are errors chore: fix bug that caused validators to error if validator func throws Noticeable with a function like ```js ow( null, ow.any( ow.string.minLength(12), ow.string.includes('owo') ) ); ``` chore: apply code style suggestion Co-authored-by: Sindre Sorhus <[email protected]> chore: fix stack generation and comment chore: move from t.assert to t.is src: add more tests to increase coverage chore: correct test messages chore: fix rebase
a69888f
to
1a91170
Compare
@sindresorhus back again, after a rebase (technically it was squash, commit, rebase, commit, commit, squash, commit), seems like everything is back in order! Probably my local branch was outdated compared to your |
Nice work. Thanks ;) |
This PR closes #5
What's been added
This PR adds multiple validation error reporting to Arguments and AnyPredicates, by attaching a
validationErrors
map to the resulting error (heavily simplified). I am open to discussion about possible alternatives, issues, concerns, or just how you would want to see this implemented instead. Personally, I believe this implementation is clean enough (at least from the UX side of things) that it shouldn't be too breaking (however it does classify as semver major). With the current implementation, you may then take the resulting errors and present them however you may want in your API for example. If the full error message is desired to show all errors, let me know and I will look into how that could be displayed in a nicer wayThe error stacktrace is also kept, currently looking like this by running the
example.js
file in the root of the repositoryIn-depth, going file by file
argument-error.ts
stack trace is now kept, as well as the error name. (and, while after running
npm run build
it will prepend that random letter for the name (can be fixed by not mangling the class names iirc), it will also output the name itself, as shown above)Made the stacktrace for browsers not lose the message or name
holds a
Map<string, string[]>
representing any validation errorsindex.ts
captureStackTrace
predicates/any.ts
now generates a different message if all of the passed predicates error out
ignores any non-ArgumentError exceptions (although... do we want that? Discussion needed)
predicates/predicate.ts
IssueHunt Summary
Referenced issues
This pull request has been submitted to: