Skip to content

Incorrect documentation for notice event #1735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tlhunter opened this issue Sep 24, 2018 · 1 comment
Closed

Incorrect documentation for notice event #1735

tlhunter opened this issue Sep 24, 2018 · 1 comment
Milestone

Comments

@tlhunter
Copy link
Contributor

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' }
@charmander charmander added this to the docs milestone Sep 25, 2018
@mitar
Copy link

mitar commented Jan 4, 2019

I do Object.assign({message: notice.message}, notice) to get a regular JavaScript object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants