-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Better error messages #12098
Better error messages #12098
Conversation
Hey @SnailBones What and where to make a change in the changelog? Also is spacing an issue bc while saving the code vscode made some automated spaces in the javascript? |
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.
Thank you for your work on this @Sugarlust!
Also is spacing an issue bc while saving the code vscode made some automated spaces in the javascript?
The spacing changes in camera.js
suggest that you ran a linter on this file (maybe prettier or beautify?) We use ESLint for linting (That's why the lint test is failing. You can run this test locally with yarn lint
).
Can you please isolate the relevant changes without the formatting changes to the file?
The changelog goes in the last entry of the Launch Checklist above. For instance:
|
@SnailBones I isolated the changes. Does it seem fine now? |
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.
@SnailBones I isolated the changes. Does it seem fine now?
Thanks for doing that @Sugarlust, that's a huge improvement!
Looking at your code, I think that your checks probably aren't doing what you think they are. Can you verify the behavior works as intended? (run yarn start-debug
and then you can call the functions in console.)
Lastly, it would be good to add a unit test in map.test.js
to ensure that this behavior doesn't break on future changes. Here's an example of a unit test checking an error message:
mapbox-gl-js/test/unit/ui/map.test.js
Lines 1957 to 1964 in 04a4447
t.test('throws error if invalid projection name is supplied', (t) => { | |
const map = createMap(t); | |
map.on('error', ({error}) => { | |
t.match(error.message, /Invalid projection name: fakeProj/); | |
t.end(); | |
}); | |
t.end(); | |
}); |
Co-authored-by: Aidan H <cassowary4@gmail.com>
Co-authored-by: Aidan H <cassowary4@gmail.com>
Co-authored-by: Aidan H <cassowary4@gmail.com>
@SnailBones I made the change in the error message in zoomTo. I don't really know how to write unit tests but I'm surely gonna give it a try. |
@SnailBones can you tell me how do I run the functions on console. What do I do after running yarn start-debug in the terminal. Should I fire this command directly or do I need to do something before? |
Instructions are on the contributing page:
Then you can open the debug console with F12 and call the functions there. |
@SnailBones Idk why but I'm not able to call the flyTo and zoomTo function. It says "undefined". also correct me if I'm wrong but to call a function we call it like "map.functionName()" right? |
@SnailBones should I just write the tests? |
@Sugarlust Yes, I'm able to reproduce this issue with
Sure! Though this may be easier if you can test the behavior in console. |
@@ -317,6 +318,13 @@ class Camera extends Evented { | |||
* }); | |||
*/ | |||
zoomTo(zoom: number, options: ? AnimationOptions, eventData?: Object): this { | |||
if (typeof zoom !== 'number'){ | |||
this.fire(new ErrorEvent(new Error( | |||
`zoom requires a number not ${zoom}`))); |
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.
`zoom requires a number not ${zoom}`))); | |
`map.zoomTo() requires a number in the first argument. ${typeof zoom} provided`))); |
Thanks for your time and contribution @Sugarlust but I'm not sure we should move it forward or go ahead with merging this PR. While this is a useful exception on developer errors, we don't have precedent of type safety errors on other APIs. Type safety is done with static type annotations, and while I imagine that not all external developer adopt the same type checking as part of their tooling, it's not trivial to exhaust every possible type checks at runtime as this is better suited for static analysis. If we introduce this, we would start to be inconsistent with other APIs and probably be asked to adopt similar patterns elsewhere. Though, I don't have an answer to improving developer experience on that regards. Maybe @mourner can weigh in as he knows more about this and could tell whether it's possible to leverage type safety across our API boundaries. cc @SnailBones |
Also referring to #9485 as it's a similar topic and something that could be researched and considered as part of addressing error handling improvements. |
Launch Checklist
@mapbox/map-design-team
@mapbox/static-apis
if this PR includes style spec API or visual changes@mapbox/gl-native
if this PR includes shader changes or needs a native portmapbox-gl-js
changelog:<changelog></changelog>