chore(idFromString): make error message friendlier#2200
Conversation
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
- The error alone is a bit cryptic, and if you're seeing it, the solution is somewhat buried in docs: https://developers.cloudflare.com/durable-objects/best-practices/access-durable-objects-from-a-worker/#parse-previously-created-ids-from-strings - This makes the `idFromString` error slightly friendlier
75ec0aa to
95eb765
Compare
|
Hey 👋, As someone who's run into this before, would it make sense to also mention |
|
@DaniFoldi I'm not able to test/repro jurisdictions related errors locally with Do the same requirements of having to first call I don't have strong opinions on including/omitting jurisdiction mention. It is also a namespace, so the current error message is still accurate w.r.t jurisdictions 😄 |
jasnell
left a comment
There was a problem hiding this comment.
I'm good with the change in general but I'm not sure it really provides much additional help.
| JSG_REQUIRE(memcmp(id + BASE_LENGTH, decoded.begin() + BASE_LENGTH, | ||
| decoded.size() - BASE_LENGTH) == 0, | ||
| TypeError, "Durable Object ID is not valid for this namespace."); | ||
| TypeError, "Durable Object ID is not valid for this namespace. Please ensure that the ID was previously created within the same namespace."); |
There was a problem hiding this comment.
Hmm, I'm not sure this really adds information. Maybe we can rephrase to something like:
Durable Object ID did not come from this namespace.
?
There was a problem hiding this comment.
@kentonv Happy to rephrase it to anything else!
The main idea behind the additional error text is to provide remediation steps during testing, which is the angle I am/was coming from.
For context into what I was doing:
- I was using a "fake" Durable Object ID in a test, like so this, and hitting the error, which I was not aware how to resolve.
- I eventually stumbled my way through the docs and found out I had to call
newUniqueId()oridFromName()in my tests first.- This additional trip through the docs is something I'm hoping the error message itself can help skip.
Ideas for rephrasing:
- Maybe the error text should mention those methods directly?
- Maybe the error text can link to docs? (This is a great DX, but it's an additional SDK-to-Web contract to maintain 😅 )
WDYT?
|
@DaniFoldi I don't think this particular error can be the result of using the wrong jurisdiction. If you use the wrong jurisdiction you'll get an ID that's valid for the namespace but points to a different object. |
Description
The error alone is a bit cryptic, and if you're seeing it, the solution is somewhat buried in docs: https://developers.cloudflare.com/durable-objects/best-practices/access-durable-objects-from-a-worker/#parse-previously-created-ids-from-strings
This makes the
idFromStringerror slightly friendlier