Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions workers/javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ export default class JavascriptEventWorker extends EventWorker {
bias: SourceMapConsumer.LEAST_UPPER_BOUND,
});

/**
* source-map-js returns nulls when the generated position is not in the map.
* Assigning them would wipe the catcher coordinates and set sourceCode to [].
*
* Fixes bug: https://github.com/codex-team/hawk.workers/issues/600
*/
if (!originalLocation.source) {
return stackFrame;
}

/**
* Source code lines
*/
Expand Down
50 changes: 50 additions & 0 deletions workers/javascript/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,56 @@ describe('JavaScript event worker', () => {
await worker.finish();
});

it('should keep the original frame when the source map has no mapping', async () => {
/**
* Arrange
*/
const worker = new JavascriptEventWorker();

jest.spyOn(worker, 'addTask');
jest.spyOn(JavascriptEventWorker.prototype as any, 'loadSourceMapFile')
.mockResolvedValue(sourceMapFileContent);
await worker.start();

const workerEvent = createEventMock({ withBacktrace: true });
const originalFrame = {
file: 'file:///main.js',
line: 9999,
column: 1,
function: 'handler',
};

/**
* Copy the frame so a mutation inside the worker cannot hide a failed lookup
*/
workerEvent.payload.backtrace = [ { ...originalFrame } ];

const release = createReleaseMock({
projectId: workerEvent.projectId,
release: workerEvent.payload.release,
});

await db.collection('releases').insertOne(release);

/**
* Act
*/
await worker.handle(workerEvent);

/**
* Assert
*/
expect(worker.addTask).toHaveBeenCalledWith(
WorkerNames.GROUPER,
expect.objectContaining({
payload: expect.objectContaining({
backtrace: [ originalFrame ],
}),
})
);
await worker.finish();
});

it('should use cache while processing source maps', async () => {
/**
* Arrange
Expand Down
Loading