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

Proper Call Stack in macros #15269

Open
brainkim opened this issue Nov 20, 2024 · 0 comments
Open

Proper Call Stack in macros #15269

brainkim opened this issue Nov 20, 2024 · 0 comments
Labels
enhancement New feature or request macros

Comments

@brainkim
Copy link

What is the problem this feature would solve?

Currently, the call stack in Bun macros do not provide helpful information. When calling the following code:

callstack.js

export function callstack() {
  return new Error().stack;
}

index.js

import {callstack} from "./callstack.ts" with {type: "macro"};
console.log(callstack());

Bun prints the following:

Error
    at callstack (/REDACTED/callstack.ts:2:13)
    at requestFetch (native:1:11)
    at <anonymous> (native:11:43)
    at <anonymous> (native:11:37)
    at requestInstantiate (native:1:11)
    at requestSatisfyUtil (native:1:11)
    at <anonymous> (native:11:83)

This call stack points to unhelpful internals and does not refernece the caller of the macro.

What is the feature you are proposing to solve the problem?

I think it would be nice if it printed something like:

Error
    at callstack (/REDACTED/callstack.ts:2:13)
    at module code (/REDACTED/index.ts:2:12)
    at callMacro (native:?:?)

My specific use-case is that I wanted to resolve relative paths in my macro asset("./favicon.ico"), and I needed the caller’s path. I went to use the callsites library but got this more or less useless stack.

I took a brief look at the code and it seems like it might be possible but requires some knowledge of JSC internals.

Bun version: 1.1.34

What alternatives have you considered?

No response

@brainkim brainkim added the enhancement New feature or request label Nov 20, 2024
@nektro nektro added the macros label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request macros
Projects
None yet
Development

No branches or pull requests

2 participants