1

I'm printing the error object in nodejs. The output of console.log(err) looks like:

{ [error: column "pkvalue" does not exist]
  name: 'error',
  length: 96,
  severity: 'ERROR'}

What is the information printed in square brackets and how to access it ?

0

2 Answers 2

1

It just common Error part
Rest is additional defined fields:

$ node
> var e = new Error('Some error');
undefined
> e.field = 'value'
'value'
> console.log(e)
{ [Error: Some error] field: 'value' }

You can access to error message as message field:

> e.message
'Some error'
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Do you know why the message is not visible as normal property when you print the error object. What is the logic behind this ?
I think it just custom toString method implementation for Error
0

You could try to use util.inspect instead, it gives more verbose information and serialize objects to strings differently.

See https://nodejs.org/api/util.html#util_util_inspect_object_options

1 Comment

Hi I've tried but util.inspect prints it exactly the same way. @vp_arth answer is what I wanted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.