Skip to content
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

PostgresError prints as {} with node --test #696

Closed
Pyrolistical opened this issue Oct 15, 2023 · 2 comments · Fixed by #698
Closed

PostgresError prints as {} with node --test #696

Pyrolistical opened this issue Oct 15, 2023 · 2 comments · Fixed by #698

Comments

@Pyrolistical
Copy link
Contributor

Pyrolistical commented Oct 15, 2023

Env:

$ node -v
v20.8.0
$ ack postgres package.json
    "postgres": "3.4.0",

Given repo.js

import { test } from "node:test";

import postgres from "postgres";
test("should print PostgresError", async () => {
  const sql = postgres(`postgres://${process.env.USER}@localhost`);
  try {
    await sql`
      invalid query
    `;
  } catch (error) {
    // console.log("error does print correctly", error);
    throw error;
  } finally {
    await sql.end();
  }
});

Run node --test repo.js

Expected

$ node --test repo.js
✖ should print PostgresError (...ms)
  PostgresError: syntax error at or near "invalid"
      at TestContext.<anonymous> (.../repo.js:12:11)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Test.run (node:internal/test_runner/test:632:9)
      at async startSubtest (node:internal/test_runner/harness:208:3)

Actual

$ node --test repo.js
✖ should print PostgresError (...ms)
  {}
@Pyrolistical

This comment was marked as outdated.

@Pyrolistical
Copy link
Contributor Author

Pyrolistical commented Oct 16, 2023

I found the issue. It is caused by the Object.create in queryError

This hack fixes the issues:

function queryError(query, err) {
    query.reject(err)
    // query.reject(Object.create(err, {
    //   stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
    //   query: { value: query.string, enumerable: options.debug },
    //   parameters: { value: query.parameters, enumerable: options.debug },
    //   args: { value: query.args, enumerable: options.debug },
    //   types: { value: query.statement && query.statement.types, enumerable: options.debug }
    // }))
  }

Pyrolistical added a commit to Pyrolistical/postgres that referenced this issue Oct 16, 2023
porsager pushed a commit that referenced this issue Oct 26, 2023
* Keep query error instead of creating creating new object

fixes #696

* Enumerate properties only if debug

* Fixed typo

* Fixed styling
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

Successfully merging a pull request may close this issue.

1 participant