surrealdb icon indicating copy to clipboard operation
surrealdb copied to clipboard

Bug: Misleading Error on improper record id encapsulation

Open mugendi opened this issue 2 years ago • 2 comments

Describe the bug

This bug is likely in the NodeJs library.

It occurs whenever one attempts to update a record with an ID that contains certain characters such as -.

Example:

   await db.change('person:e030f6a5-5b11-4cde-adfb-e81d0e12d6e0', user);

This throws the error:

ERROR r [PermissionError]: Unable to update record: person:e030f6a5-5b11-4cde-adfb-e81d0e12d6e0
    at c.Ze (/home/mugz/projects/node/tests/surreal/node_modules/surrealdb.js/dist/lib/index.cjs:1:70635)
    at c.<anonymous> (/home/mugz/projects/node/tests/surreal/node_modules/surrealdb.js/dist/lib/index.cjs:1:68948)
    at c.r (/home/mugz/projects/node/tests/surreal/node_modules/surrealdb.js/dist/lib/index.cjs:1:52384)
    at /home/mugz/projects/node/tests/surreal/node_modules/surrealdb.js/dist/lib/index.cjs:1:52586
    at Array.forEach (<anonymous>)
    at c.value (/home/mugz/projects/node/tests/surreal/node_modules/surrealdb.js/dist/lib/index.cjs:1:52563)
    at s.<anonymous> (/home/mugz/projects/node/tests/surreal/node_modules/surrealdb.js/dist/lib/index.cjs:1:65324)
    at /home/mugz/projects/node/tests/surreal/node_modules/surrealdb.js/dist/lib/index.cjs:1:52586
    at Array.forEach (<anonymous>)
    at s.value (/home/mugz/projects/node/tests/surreal/node_modules/surrealdb.js/dist/lib/index.cjs:1:52563)

Steps to reproduce

Send any query with a uuid as record id i.e (table:uuid) without quoting the id value in `` quotes.

Expected behaviour

While we should expect an error, the current PermissionError being thrown is misleading. We should expect a FormattingError or something along those lines.


We should also add a note somewhere in the documentation about SurrealQL spacial characters and escaping query statements.

SurrealDB version

1.0.0-beta.7

Contact Details

No response

Is there an existing issue for this?

  • [X] I have searched the existing issues

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

mugendi avatar Sep 13 '22 21:09 mugendi

Have you tried changing your code to include the ` character around complex IDs (specifically in this case using a dash). I had the same problem in my project, but in the docs here it said:

Record IDs can contain complex characters, surrounded by the ` character.

So I believe if you change your code to the following everything should work.

 await db.change('person:\`e030f6a5-5b11-4cde-adfb-e81d0e12d6e0\`', user);

Alternatively you can use and also shown in the docs.

 await db.change('person:⟨e030f6a5-5b11-4cde-adfb-e81d0e12d6e0⟩', user);

titusdmoore avatar Sep 20 '22 13:09 titusdmoore

@titusdmoore true, changing makes everything work. But this bug is about the error being reported when things don't work. The error is incorrect and misleading and thus anyone else who comes across this error, and does not know their mistake will waste time looking in the wrong places. That was my case until I contacted @tobiemh and he helped me out.

mugendi avatar Sep 27 '22 10:09 mugendi