Skip to content
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

Display better message + emit error when bad args are passed to map camera events #4385

Closed
mollymerp opened this issue Mar 9, 2017 · 13 comments
Assignees

Comments

@mollymerp
Copy link
Contributor

Right now if you call map.zoomTo([0,0]) we get the 'failed to invert matrix' and the map breaks. We should emit a syntax error with a clear message.

Similarly, when you pass a coordinate pair to map.flyTo the map doesn't break, it just doesn't do anything. We should emit an error there as well and investigate other potentially affected methods.

cc @geografa

@ryanhamley
Copy link
Contributor

ryanhamley commented May 24, 2018

Seems to happen on scroll zoom as well, as seen here #6486

Is this a bug that should be fixed or is it enough to surface better errors?

@HarelM
Copy link

HarelM commented Apr 16, 2019

I had the same issue when calling flyTo with zoom: null. since the stack trace doesn't reveal the origin of this error message I had to comment out pieces of my code until I found the root cause.
A good error message would've saved me a few hours.
I was migrating from openlayers where zoom is optional and thus was not aware this function can cause this error...

@acharyasourav
Copy link

As a beginner in opensource, I would like to work on this. Can you tell me where I should start looking?

@SnailBones
Copy link
Contributor

Thank you @Sugarlust!

Just to make sure there's no confusion on this front, Mapbox GL JS is no longer fully open source. Here's the current license. You'll need to sign a contributor's agreement to submit a pull request.

The functions in question are in camera.js:

zoomTo(zoom: number, options: ? AnimationOptions, eventData?: Object): this {

flyTo(options: EasingOptions & {preloadOnly?: boolean}, eventData?: Object): this {

You can look in map.js for examples of throwing error events:

mapbox-gl-js/src/ui/map.js

Lines 2195 to 2198 in 2bc4599

this.fire(new ErrorEvent(new Error(
`The width and height of the updated image (${width}, ${height})
must be that same as the previous version of the image
(${existingImage.data.width}, ${existingImage.data.height})`)));

Lastly, we need a unit test for this behavior, probably in map.test.js

The contributor guide will get you set up to develop the library, feel free to ping me with any questions not covered there and to tag me for review on your PR.

@acharyasourav
Copy link

Hey, @SnailBones I checked out the snippets of code you mentioned. Can you tell me what criteria I need to check to fire up the error message in those functions? Also what actually is OBJECT in

flyTo(options: EasingOptions & {preloadOnly?: boolean}, eventData?: Object): this {

@SnailBones
Copy link
Contributor

Can you tell me what criteria I need to check to fire up the error message in those functions?

I think the criteria should be that the input to the functions is of the correct type. So we should throw the error if the first argument is not a number inzoomTo or object in flyTo.

Also what actually is OBJECT in

We use Flow for type-checking, it's similar to TypeScript. Objectis the Flow type of eventData. Type-checking in JavaScript validates the source code but doesn't prevent the user from passing in invalid inputs, which is why we need to throw an error in these cases.

@acharyasourav
Copy link

acharyasourav commented Jul 12, 2022

Thanks, @SnailBones, So all I need to do is add an if condition that checks:

  • zoom is not a number in zoomTo

    zoomTo(zoom: number, options: ? AnimationOptions, eventData?: Object): this {

  • and in flyTo if eventData does not have an object

    flyTo(options: EasingOptions & {preloadOnly?: boolean}, eventData?: Object): this {

  • and then simply add error messages for the following.

is that right?

Also if there's an IRC or discussion page please let me know.

@acharyasourav
Copy link

acharyasourav commented Jul 18, 2022

Hey, @SnailBones can you check these out. Do these sound correct what other changes should I make?

https://github.com/Sugarlust/mapbox-gl-js/blob/febd320d180aeaa0a3e2f20c3778dac7b8f5ad2c/src/ui/camera.js#L320-L329

https://github.com/Sugarlust/mapbox-gl-js/blob/febd320d180aeaa0a3e2f20c3778dac7b8f5ad2c/src/ui/camera.js#L1454-L1460

Also, where can I find the contributor's license to sign, and is there a discussion channel or IRC?

@SnailBones
Copy link
Contributor

@Sugarlust looks like you're on the right track to me! I think the error messages could benefit from being more specific, e.g. "Map.flyTo accepts an object, not [type of input]"

The contributor's agreement will be available to you when you submit a PR.

@SnailBones
Copy link
Contributor

A PR would be great, thank you!

@acharyasourav
Copy link

@SnailBones I just made a PR #12098 can you please help me through it, I'm a bit confused?

@SnailBones SnailBones linked a pull request Jul 22, 2022 that will close this issue
10 tasks
@SnailBones
Copy link
Contributor

Closing this ticket as fixing it in isolation goes against our usage of Flow for type checking.

From #12098 (comment):

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.

This issue is still tracked in #9485 and should be considered in the context of broader improvements to error handling.

Thank you for your time and contribution @Sugarlust!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants