Skip to content

[Q] Is it possible to get a stack trace with both line numbers and column numbers? #238

@toyboot4e

Description

@toyboot4e

About

Take this code as an example:

const f = () => {
throw new Error();
};

f();

Actual behavior

With quickjs-emscripten, the stack trace only shows line numbers:

    at f (example.js:3)
    at <eval> (example.js:6)

Desired behavior

In developer tool's console, it shows column numbers, too:

Uncaught Error
    at f (<anonymous>:2:7)
    at <anonymous>:5:1

How to reproduce

Here's repro.ts:

import { errors, getQuickJS } from "npm:quickjs-emscripten";

const QuickJS = await getQuickJS();
const vm = QuickJS.newContext();

const code = `
const f = () => {
throw new Error();
};

f();
`;
const evalResult = vm.evalCode(code, 'example.js');

try {
  const result = vm.unwrapResult(evalResult);
  throw new Error('unreachable!');
} catch (e: unknown) {
  if (e instanceof errors.QuickJSUnwrapError && e.cause && typeof e.cause === 'object' && 'stack' in e.cause) {
    console.log(e.cause.stack);
  }
}

The result is as follows. It only contains line numbers:

$ deno run repro.ts
    at f (example.js:3)
    at <eval> (example.js:6)

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