question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getTerrainRgb returns Promise { <state>: "rejected" }

See original GitHub issue

Problem:

the getTerrainRgb method returns a rejected Promise

I’m calling the following inside a useEffect() React hook:

const ioToken = <mytoken>
const tgeo = new ThreeGeo({
                    tokenMapbox: ioToken,
});

async function fetchGeo() {
    const terrain = await tgeo.getTerrainVector(
                        [0.0, 0.0], // [lat, lng]
                        1.0,               // radius of bounding circle (km)
                        13)               // zoom resolution
    fgRef.current.scene().add(terrain)
                    };               

fetchGeo();

what happens The getTerrainRgb method returns a rejected Promise

additional comments The fgRef.current.scene().add() method is from react-force-graph.

I’ve checked that the mapbox API token is valid.

Any ideas why it’s not working?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JonThomcommented, Dec 7, 2020

@j-devel I can see in the console that the Promise is no longer rejected, so yes, I consider it solved! (I didn’t reply earlier because I encountered another issue - probably not from three-geo - preventing the addition of the terrain to the scene.) Thanks to @Cobertos for the pro debugging and to @j-devel for the fix!

1reaction
j-develcommented, Dec 1, 2020

Thanks @Cobertos for feedback!

  • Please don’t strip console.errors from your builds (looks like this is from drop_console in es-pack-js)

Addressed in https://github.com/w3reality/es-pack-js/commit/d93a7432a261712ed058540066d603ab06ea21df

  • Don’t reject null, reject with the err so at least the external developer can catch it and act on it.
  • Final error seems to be coming from resolveGetPixels. I’m building this with webpack for a browser with Nuxt, so maybe something about the build environment is triggering the wrong code path?

Fixed in cda26f3. The latest v1.4.3 build in dist should just work as far as you use them in browsers.

For NodeJS users, I’ve introduced a new flag option instead of implicitly relying on the crude isNodeJS() method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When Promise state become rejected or resolved
The promise that is resolved is not the original promise, but the promise returned by then . The original promise is indeed rejected, ......
Read more >
Promise.reject() - JavaScript - MDN Web Docs
The Promise.reject() method returns a Promise object that is rejected with a given reason.
Read more >
JavaScript Promise Tutorial – How to Resolve or Reject ...
The results will contain a state (fulfilled/rejected) and value, if fulfilled. In case of rejected status, it will return a reason for the...
Read more >
JavaScript promise reject() Method - GeeksforGeeks
Return value: It returns the rejected promise with the given reason, either specified by user or via the backend. The examples below illustrate ......
Read more >
Error handling with promises - The Modern JavaScript Tutorial
https://uploads.disquscdn.c... In this case, when the callback is executed, reject returns a promise object with updated properties i.e. state = ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found