What is a node-postgres Error object? Why does node console.log and JSON.stringify handle it differently?

console.log displays it as follows:

{ [error: syntax error at or near "step"]
  length: 86,
  name: 'error',
  severity: 'ERROR',
  code: '42601',
  detail: undefined,
  hint: undefined,
  position: '62',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  file: 'scan.l',
  line: '1001',
  routine: 'scanner_yyerror' }

but JSON.stringify does not see the narrative of the error,

{"length": 86, "name": "error", "severity": "ERROR", "code": "42601", "position": "62", "file": "scan.l", " line ":" 1001 "," regular ":" scanner_yyerror "}

I cannot figure out how to get this "error: the column" undefined "does not exist" reading the wiki ( https://github.com/brianc/node-postgres/wiki/Error-handling , http://nodejs.ru/doc /v0.4.x/stdio.html#console.log )

The code is

   client.query(selstring, function(err, result) {
   if(err){
     res.send(JSON.stringify(err));
     console.log(err);
   }else{

thank

UPDATE: err.toString() error: syntax error at or near "step"

+5
4

pg Js Error() obj, "description" err.message...

console.log(new Error("hello world"));
[Error: hello world]
console.log(new Error("hello world").message);
hello world

Error objs, Error.prototype

. JavaScript?

+5

,

console.log(query.text);

http://dailyjs.com/2011/09/26/heroku/

0

, . . github.

var pg_conn_conf = {
  username: 'user',
  pass: 'pass',
  port: 5432,
  host: 'localhost',
  db: 'mydb'
};

fooobar.com/questions/39834/..., Error.prototype, , . .

0

.

JSON.stringify(err), , . ? - , - , JSON.stringify.

I found that err.message really works to access the string, but I really don’t understand why, since the “message” does not appear as an attribute in the string version. If the "message" is an err attribute, why doesn't it appear in stringify output? If this is not so, then where is it from?

-1
source

All Articles