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

Better error message for invalid value #275

Open
haikyuu opened this issue Feb 24, 2022 · 5 comments
Open

Better error message for invalid value #275

haikyuu opened this issue Feb 24, 2022 · 5 comments

Comments

@haikyuu
Copy link

haikyuu commented Feb 24, 2022

$ node script.js
edgeql-js/syntax/toEdgeQL.ts:1188
      throw new Error(`Invalid value for type ${type.__name__}`);
            ^

Error: Invalid value for type std::json
    at null.literalToEdgeQL 

A better error Invalid value for type std::json at property metadata in default::User

@haikyuu
Copy link
Author

haikyuu commented Feb 24, 2022

another one

EdgeQLSyntaxError: character U+202E is not allowed, use escaped form \u202e

@colinhacks
Copy link
Contributor

colinhacks commented Mar 1, 2022

Can you show some code examples here? Ideally TypeScript would catch these errors at compile time (at least the first one).

@haikyuu
Copy link
Author

haikyuu commented Mar 9, 2022

@colinhacks Yes
The following throws that error

const profile = '{"type": "json"}' 
const user = { github_profile: profile }
const iq = e.insert(e.User, user)

It's fixed by using e.json(profile) instead

@haikyuu
Copy link
Author

haikyuu commented Mar 9, 2022

The second one happened because of a right to left override character which is not supported without using the escaped form.
You can reproduce using this

edgedb> select 'rekcäH nitraM‮'
error: EdgeQLSyntaxError: character U+202E is not allowed, use escaped form \u202e
  ┌─ query:1:8
  │
1 │ select '‮rekcäH nitraM‮';
  │        ^ error 

A better error would maybe include the full generated query?
I was trying to insert a user using e.insert(e.User, user)
Actual error that the query builder throws

EdgeQLSyntaxError: character U+202E is not allowed, use escaped form \u202e

@haikyuu
Copy link
Author

haikyuu commented Mar 9, 2022

Another one

InvalidValueError: cannot extract elements from a scalar
    at RawConnection._parseErrorMessage (/Users/abdellah/workspace/scrimba/scrimba-edge/node_modules/edgedb/dist/rawConn.js:371:21)
    at RawConnection._executeFlow (/Users/abdellah/workspace/scrimba/scrimba-edge/node_modules/edgedb/dist/rawConn.js:861:34)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RawConnection.fetch (/Users/abdellah/workspace/scrimba/scrimba-edge/node_modules/edgedb/dist/rawConn.js:981:13)
    at async Transaction._runOp (/Users/abdellah/workspace/scrimba/scrimba-edge/node_modules/edgedb/dist/transaction.js:94:20)
    at null.<anonymous> (/Users/abdellah/workspace/scrimba/scrimba-edge/dbschema/pg_migrations/users.imba:148:24)
    at async ClientConnectionHolder.transaction (/Users/abdellah/workspace/scrimba/scrimba-edge/node_modules/edgedb/dist/client.js:135:26)
    at async Client.transaction (/Users/abdellah/workspace/scrimba/scrimba-edge/node_modules/edgedb/dist/client.js:450:20)
    at null.run (/Users/abdellah/workspace/scrimba/scrimba-edge/dbschema/pg_migrations/users.imba:101:8)

This happened on a query like so (but with a more complex type)

const query = e.params(
  {raw_data: e.array(e.tuple({title: e.str}))},
  params =>
    e.for(e.array_unpack(params.raw_data), item =>
      e.insert(e.Movie, {
        title: item.title,
      })
    )
);
console.log(query.toEdgeQL());
const result = await query.run(client, {
  raw_data: [
    {title: "The Marvels"},
    {title: "Blade"},
    {title: "Doctor Strange and the Multiverse of Madness"},
  ],
});

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

No branches or pull requests

3 participants