Error messages for humans #186

Closed
bjornharrtell opened this Issue Sep 15, 2012 · 6 comments

Comments

4 participants

Errors reported on a failing query are highly technical, refering to internal postgresql code, and lacks information about what really is the cause of the failure. Example when specifying a column name which does not exist:

{"length":93,"name":"error","severity":"ERROR","code":"42703","position":"51","file":"parse_expr.c","line":"766","routine":"transformColumnRef"}

In pgAdmin you get "ERROR: column "name" does not exist". A similar message should be available in node-postgres.

Owner

brianc commented Dec 11, 2012

Do the friendly strings exist somewhere within postgres? If they do, it's probably possible to map them with a couple lines of code in user space. I do believe the error you're referencing should have a message property as well, though. Do you have some code to reproduce the error?

If the error strings don't exist within then they're hard-coded within pgAdmin. I am not going to re-implement them.

@ghost

ghost commented Dec 11, 2012

Thanks! I'll try to look into this and get back to you with more information.

@ghost

ghost commented Dec 11, 2012

Strings do exist in the postgres code base, see:
https://github.com/postgres/postgres/blob/master/src/backend/utils/errcodes.txt

It seems there are macros that facilitate the usage of the above file in the postgres source when errors occur. Example in the clause parser when clause contains an invalid column reference:
https://github.com/postgres/postgres/blob/master/src/backend/parser/parse_clause.c#L1443

Contributor

whitelynx commented May 2, 2013

This issue seems to be resolved; when I trigger an error in a SQL statement, here's the errors I get back (printed with util.inspect):

Error from js client: { [error: column "bleh" does not exist]
  length: 91,
  name: 'error',
  severity: 'ERROR',
  code: '42703',
  detail: undefined,
  hint: undefined,
  position: '8',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  file: 'parse_expr.c',
  line: '766',
  routine: 'transformColumnRef' }
Error from native client: { [Error: column "bleh" does not exist]
  severity: 'ERROR',
  code: '42703',
  position: '8',
  file: 'parse_expr.c',
  line: '766',
  routine: 'transformColumnRef' }

I am somewhat curious why file: 'parse_expr.c', line: '766' still shows up in the errors from the JS client, though.

Actually version 0.8.4 behaves the same so there never was an issue. The reason why I wasn't getting meaningful errors was that I didn't realize that the error object is derived from the built in Error type which does not behave as expected when serialised to JSON which I was doing (result is an incomplete representation without the meaningful message "property"). I'm still a bit confused why the Error type isn't behaving as a normal object...

Closing since there isn't any issue here, except perhaps that the error type should be documented better.

Collaborator

booo commented May 12, 2013

@whitelynx The postgres server is written in c. We don't parse the query on the client side (js) aka the driver. The request is in text or binary form and we have to parse it to perform the actual query.

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