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

Add bun compatibility #1804

Closed
wants to merge 1 commit into from
Closed

Add bun compatibility #1804

wants to merge 1 commit into from

Conversation

AaronDewes
Copy link

Fixes #1802. I'm not sure if this is something you want, but it's an easy fix that doesn't break anything. This has been tested in both Node and Bun.

The underlying issue in Bun is probably harder for their team to fix, because it would very likely require changes to WebKit.

Fixes pinojs#1802. I'm not sure if this is something you want, but it's an easy fix that doesn't break anything.

The underlying issue in Bun is probably harder for their team to fix, because it would very likely require changes to WebKit.
@kibertoad
Copy link
Contributor

Bun doesn't support Errors? Or Errors don't have stack?

@AaronDewes
Copy link
Author

Bun doesn't support Errors? Or Errors don't have stack?

Currently, Error.stack ignores Error.prepareStackTrace because of a bug in Bun.

@AaronDewes
Copy link
Author

@robobun

function noOpPrepareStackTrace (_, stack) {
  return stack
}

function getCallers() {
  const originalPrepare = Error.prepareStackTrace
  Error.prepareStackTrace = noOpPrepareStackTrace
  const stack_default = new Error().stack
  const tmpError = {};
  Error.captureStackTrace(tmpError)
  const { stack } = tmpError;
  Error.prepareStackTrace = originalPrepare;
  console.log(`new Error().stack: typeof stack.default == ${typeof stack_default}`);
  console.log(Error.captureStackTrace(targetObj); typeof targetObj.stack == ${typeof stack}`);
}

function main() {
  getCallers();
}

main();

@AaronDewes
Copy link
Author

I have no idea if this bot still works, but the above code is an example for the bug in bun.

@kibertoad
Copy link
Contributor

kibertoad commented Sep 10, 2023

If it's just a bug in Bun, I'm -1 on this change, this seems hacky and brings no benefits to the library itself.

update: thought about it more, I'm OK with this, if there is Bun ticket linked in todo in comment next to this change with explanation.

@kibertoad
Copy link
Contributor

kibertoad commented Sep 10, 2023

@AaronDewes please see updated comment. People are starting to experiment with bun, we probably don't want to block them.

can you benchmark perf of both approaches?

@AaronDewes
Copy link
Author

It looks like it decreases performance:

function noOpPrepareStackTrace (_, stack) {
    return stack
}

const originalPrepare = Error.prepareStackTrace
Error.prepareStackTrace = noOpPrepareStackTrace

// Method 1: Using new Error().stack
console.time('Method 1');
for (let i = 0; i < 100000; i++) {
  const stack = new Error().stack;
}
console.timeEnd('Method 1');

// Method 2: Using Error.captureStackTrace()
console.time('Method 2');
for (let i = 0; i < 100000; i++) {
  let tmpError = {};
  Error.captureStackTrace(tmpError);
  const { stack } = tmpError;
}
console.timeEnd('Method 2');

Error.prepareStackTrace = originalPrepare

Node:

Method 1: 231.382ms
Method 2: 249.456ms

Bun:

[73.06ms] Method 1
[100.05ms] Method 2

@mcollina
Copy link
Member

I'm -1 for this change. Open a bug in Bun. This also broke all the tests, so possibly there is something wrong too in your implementation.

As long as Bun does not support running tap tests, it's very hard for us to land these PR... because there is no way to know that pino is actually working.

@mcollina
Copy link
Member

@AaronDewes AaronDewes closed this Sep 10, 2023
@AaronDewes
Copy link
Author

Thanks! I was aware that Bugs in Bun should be fixed, but I thought this is a simple fix for Pino too.

I wouldn't file an issue for bugs in Bun to JS projects, but if something can be fixed easily, I thought a PR would be helpful, but I understand your reasoning.

@kibertoad
Copy link
Contributor

@AaronDewes Appreciate you sending in the PR either way! It's always great to see people doing something about topics that they care about.

@christophemarois
Copy link

As an update for interested future readers, this will apparently be fixed in bun 1.0.3 oven-sh/bun#4280 (comment)

Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undefined is not an object (evaluating 'callers')
4 participants