Closed vladfrangu closed 3 years ago
This change will need a lot more tests.
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 π
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 way
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.
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 validationErrors
property public so users can present it any way they wish
ArgumentError: Expected `input` to be of type `string` but received type `number`
Expected string `input` to have a minimum length of `10`, got `10`
Expected string `input` to end with `owo`, got `10`
at ow (C:\Users\Vlad\Desktop\ow\dist\index.js:21:23)
at fn (C:\Users\Vlad\Desktop\ow\example.js:13:2)
at C:\Users\Vlad\Desktop\ow\example.js:17:2
at logError (C:\Users\Vlad\Desktop\ow\example.js:6:3)
at Object.<anonymous> (C:\Users\Vlad\Desktop\ow\example.js:16:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
validationErrors: Map(1) {
'input' => [
'Expected `input` to be of type `string` but received type `number`',
'Expected string `input` to have a minimum length of `10`, got `10`',
'Expected string `input` to end with `owo`, got `10`'
]
}
}
Seems like the code coverage is below the threshold.
Seems like the code coverage is below the threshold.
That's..confusing to say the least.. I can't even see why on codecov, and on local npm run test
, I get this
A lot of these aren't even caused by me... Maybe I should try a rebase?
@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 master
and caused codecov to not report right. π
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: - [#5: Report multiple type errors](https://issuehunt.io/repos/105227249/issues/5) ---