How do I access this Javascript mysql error object (Nodejs)?

More details below, but the question is is the below a valid javascript object and how do I access that first array type thing

{ [some-text-here-without-quotes] key1: 'text', key2: 1, key3: '23000', key4: 0 }

Building an app with Nodejs, Express and MySQL. I have decided to use the 'mysql' library found in NPM at this link:

While testing I purposely created a duplicate entry condition that violated a unique constraint because I wanted to see what the returned error object looks like.

When I console.log(error) from the query the following is what prints:

{ [Error: ER_DUP_ENTRY: Duplicate entry 'abcdefg' for key 'token_UNIQUE'] code: 'ER_DUP_ENTRY', errno: 1062, sqlState: '23000', index: 0 }

I must be missing something obvious. But I cannot seem to access the data in that first array looking thing. The part of the object that starts with [Error: and ends with 'token_UNIQUE']

How do I access that part of the object?

(also, first I thought it was an improperly formatted object string or something buggy from the mysql library but underscore.js says it is an object

_.isObject(error); //true


got the exact same problem, and i still dont understand what that particular syntax means.. however, i managed to access this part of the object by force casting it into a string, by merely concatenating it to a string contant :

if (error) {    
    errmsg=" "+error   <---- cast to string here
    error.msg=errmsg;  <---- then back into the object as a tring

You can do


This will give you the list of keys that are contained in the err object. From that, you can pick the keys of your intereste. (or) you can use,


to print the object in a formatted way.

maybe the answer is a little bit late, I encountered this problem yesterday. but the solution is simple, just use toString()


error.message maybe a formal way

both methods above returning the same output

Need Your Help

javascript objects alternative syntax

javascript object syntax photoshop

I have just started scripting for photoshop using javascript

CSS:: Is there any CSS element inspector (or plugin)?

html css firefox plugins xpi

I was wondering if there is a CSS element inspector so you can easily copy an element completely AND all it's (USED ONLY) CSS properties.