microsoft / microsoft/TypeScript

Sourcemap for async function with target es2015 has missing line

Đang mở
#45,581 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Bug Domain: Source Maps
Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Mô tả

Bug Report

Async functions are downleveled to a generator, using the __awaiter wrapper.
If an async function throws an exception, the stack trace includes the call to __awaiter and then the internals of __awaiter in the following frames. The problem is with how to map those to source code.

Using importHelpers and noEmitHelpers helps with producing stable stack frames for the __awaiter internals, that can be mapped back to tslib.
However, the very call to __awaiter in my app code is still inlined, and it currently doesn't have any mapping.

This makes it a problem with tools that rely on stable stack traces. Logging tools, such as Sentry, heavily use mapped stack traces to group multiple occurrences of the same error into a single bucket. Inability to map some frames prevents such grouping, which results in all sorts of problems when monitoring the app in production (false alarms, noise on the dashboard).

Similar issues about async sourcemaps - which I still believe describe different problems than mine:

🔎 Search Terms

sourcemap, async, awaiter, generator

🕗 Version & Regression Information

I tested it in 3.5, 4.2 and 4.3. Probably it has always been the case.

⏯ Playground Link

Playground link with relevant code

Here I enabled source maps. If you decode it, you can see that there is no mapping for line (2) (the __awaiter(this, void 0, void 0, function* () call). Yet, this line is present in the stack trace.

💻 Code
// original.ts

async function callAsync() {
  throw new Error('sync')
}

callAsync()
// compiled.js

function callAsync() {
    return __awaiter(this, void 0, void 0, function* () { // <----- This line (2) is present in error stack trace
        throw new Error('sync');
    });
}
callAsync();
🙁 Actual behavior

Stack trace includes line (2) (the one with the awaiter call). However, the sourcemap doesn't have a mapping for this line

🙂 Expected behavior

I don't know, frankly. Why don't we map this line to the declaration of our async function (source line 1)? Or to the declaration of the awaiter helper?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện trường hợp từ original.ts và compiled.js bằng cấu hình Playground được liên kết, sau đó giải mã inline source map và so sánh nó với dòng stack trace cho lệnh gọi __awaiter. Làm rõ đích ánh xạ dự kiến cho dòng đó và xác minh ánh xạ thu được với target ES2015 khi bật importHelpers và noEmitHelpers.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, typescript
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.