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
Functions should throw exception on invalid args #7128
Comments
After discussion #7397 we've found that I believe that it's very important to catch such errors early, but we may also consider possible performance penalties. |
When a single non-point and non-object argument is passed to
In our problem case of a single number being passed, the
A check in
|
If you want to implement this yourself then better discuss all details in new PR. This issue is created to discuss general questions, e.g. how far should we go in arguments validation.
|
Some functions are protected with such code: Lines 30 to 37 in 436430d
Unfortunately, this allows even weirdest coercion cases, turning And also many places using Leaflet/src/layer/vector/Circle.js Line 35 in 436430d
Consider case Also #7761 |
There is also a problem with Tiles. If the Leaflet/src/layer/tile/TileLayer.js Lines 209 to 220 in d6d6051
|
In general I believe that it's better when functions called with invalid argument throw early, because such approach leaves less space for bugs.
Question is how far should we go implementing this, considering that we have no builtin facilities like languages like TypeScript have.
For example see #7125.
There is no explicit type checking, but code is composed with type-checking in mind, and intentionally fails on many cases of invalid args.
Anyway, it should not be a problem to fix (or even remove) tests when we will need that.
DomEvent.off
doesn't fail if pass invalid object instead ofel
. And (in other functions)event
argument is not validated at all.All such cases could be covered with explicit type checking, but I suppose that would be overkill.
Thoughts?
The text was updated successfully, but these errors were encountered: