Skip to content

error: invalid message format (08P01) - strings containing "\u0000" #2936

@gtargino

Description

@gtargino
error: invalid message format
    at Parser.parseErrorMessage (/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:512:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 81,
  severity: 'ERROR',
  code: '08P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'pqformat.c',
  line: '640',
  routine: 'pq_getmsgend'
}

This error is happening when I'm trying to insert some data and the query string contains: '\u0000'. The following insert works well when run directly in psql and pgAdmin. It fails using the node-postgres lib, I think something breaks in the internal parsing process.

INSERT INTO "users"
VALUES ('8c2bcd24-cd77-4e60-9482-7a5ef17965af','The \u0000 User');

I'm replacing '\u0000' to avoid this error, like this:

let query = `INSERT INTO "users"
VALUES ('8c2bcd24-cd77-4e60-9482-7a5ef17965af','The \u0000 User');`;

query = query.replace(/\u0000/g, '');

client.query(query);

Some unicodes like '\u0014' work fine. I haven't tested others.

Note: I only noticed the existence of the '\u0000' inspecting the string in vscode, for some reason this is not displayed in regular prints like console.log().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions