Skip to content

Incorrect documentation for notice event #1735

Closed
@tlhunter

Description

@tlhunter

According to the website documentation the notice event receives a string. However it actually receives an instance of Error with custom properties added:

docs:

client.on('notice', (notice: String) => void) => void

actual:

{
  client.on('notice', (notice) => {
    console.log(notice instanceof Error); // logged below
    assert.equal(notice.name, 'notice');
    assert.equal(notice.message, 'oh no');
    // console.log('client on notice', notice);
    // console.log('keys', Object.keys(notice));
    // console.log('stack', notice.stack);
    assert.ok(!notice._parentObject, 'got parent object in notice');
  });

  client.query("DO language plpgsql $$ BEGIN RAISE NOTICE 'oh no'; END $$;", () => {
  });
}
{ notice: oh no
    at Connection.parseE (.../node_modules/pg/lib/connection.js:553:11)
    at Connection.parseN (.../node_modules/pg/lib/connection.js:586:18)
    at Connection.parseMessage (.../node_modules/pg/lib/connection.js:381:19)
    at Socket.<anonymous> (.../node_modules/pg/lib/connection.js:119:22)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:607:20)
  name: 'notice',
  length: 122,
  severity: 'NOTICE',
  code: '00000',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: 'PL/pgSQL function inline_code_block line 1 at RAISE',
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'pl_exec.c',
  line: '3337',
  routine: 'exec_stmt_raise' }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions