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

Incorrect stack trace remaps #1559

Closed
kitsonk opened this issue Jan 22, 2019 · 3 comments
Closed

Incorrect stack trace remaps #1559

kitsonk opened this issue Jan 22, 2019 · 3 comments
Labels
bug Something isn't working correctly
Milestone

Comments

@kitsonk
Copy link
Contributor

kitsonk commented Jan 22, 2019

It took me a while to narrow it down, but I had been noticing that stack traces a lot of the time were not remapping properly and I was able to narrow down a reproduction.

It requires at least two modules, where one of the modules has type annotations that are getting erased. So given:

a.ts

export interface Foo {
  a: string;
  b: string;
}

export function foo(): number {
  return (undefined as any).indexOf();
}

a_test.ts

import { test, assert } from "https://deno.land/x/std/testing/mod.ts";
import { foo } from "./a.ts";

test(function test() {
  assert.equal(foo(), 0);
});

I get the following failure and stack trace:

$ deno a_test.ts
Compiling /Users/kkelly/github/deno_std/a_test.ts
running 1 tests
test test ... FAILED
TypeError: Cannot read property 'indexOf' of undefined
    at foo (/Users/kkelly/github/deno_std/a.ts:2:22)
    at test (/Users/kkelly/github/deno_std/a_test.ts:4:18)
    at runTests (/Users/kkelly/.deno/deps/https/deno.land/x/std/testing/mod.ts:154:19)
    at fire (gen/bundle/main.js:7628:7)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

/Users/kkelly/.deno/deps/https/deno.land/x/std/testing/mod.ts:181:18
            throw new Error(`There were ${failed} test failures.`);

Error: There were 1 test failures.
    at setTimeout (file:///Users/kkelly/.deno/deps/https/deno.land/x/std/testing/mod.ts:245:13)
    at fire (deno/js/timers.ts:131:3)

In particular it is saying the error occurred at a.ts:2:22 which should be a.ts:7.29.

If a.ts doesn't have types, that are erased, then the mapping isn't wrong. If there is only a single module involved, even if that module exports something and contains erased types, then the mapping isn't wrong.

@ry ry added the bug Something isn't working correctly label Jan 22, 2019
@ry ry added this to the v0.3 milestone Jan 22, 2019
@ry
Copy link
Member

ry commented Jan 22, 2019

Thanks good test case. I will look into it soon

@ry
Copy link
Member

ry commented Feb 12, 2019

So with recent changes this is almost fixed, but not quite.

We have the ability to apply source maps and colors to exceptions using the "FormatError" op. The console.error() function apply this op if its passed an exception:

deno/js/console.ts

Lines 268 to 269 in a21a5ad

const errorJSON = libdeno.errorToJSON(value);
return formatError(errorJSON);

However in the testing library we print e.stack instead of e itself:
https://github.com/denoland/deno_std/blob/d895c60a51e7cdbf517fee226ffb0274904979f8/testing/mod.ts#L268

So I think the fix should be to apply this patch in deno_std

diff --git a/testing/mod.ts b/testing/mod.ts
index 06089a8..e8e00ca 100644
--- a/testing/mod.ts
+++ b/testing/mod.ts
@@ -265,7 +265,7 @@ export async function runTests() {
       result = red_failed();
       console.log("...", result);
       console.groupEnd();
-      console.error((e && e.stack) || e);
+      console.error(e);
       failed++;
       if (exitOnFail) {
         break;

When the following PR lands in core, we can close this issue: denoland/std#190

ry added a commit to ry/deno_std that referenced this issue Feb 12, 2019
ry added a commit to ry/deno_std that referenced this issue Feb 12, 2019
ry added a commit to ry/deno_std that referenced this issue Feb 12, 2019
ry added a commit to denoland/std that referenced this issue Feb 12, 2019
@ry
Copy link
Member

ry commented Feb 19, 2019

This is fixed now.

@ry ry closed this as completed Feb 19, 2019
ry added a commit to ry/deno that referenced this issue Oct 9, 2019
caspervonb pushed a commit to caspervonb/deno_std that referenced this issue Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

No branches or pull requests

2 participants