From 9515e2f091f2cfccc13e19e43060d7d15b0628a9 Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Fri, 22 Aug 2025 02:07:51 +0300 Subject: [PATCH 1/2] Js worker fix (#445) * fix(): move logs after the conditions * chore(): fix error sending * fix(): do not use jsx parser * chore(): leave todo * chore(): do not use getFunctionContext --- workers/javascript/src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/workers/javascript/src/index.ts b/workers/javascript/src/index.ts index 95218bdf..7af09867 100644 --- a/workers/javascript/src/index.ts +++ b/workers/javascript/src/index.ts @@ -233,9 +233,9 @@ export default class JavascriptEventWorker extends EventWorker { */ lines = this.readSourceLines(consumer, originalLocation); - const originalContent = consumer.sourceContentFor(originalLocation.source); + const _originalContent = consumer.sourceContentFor(originalLocation.source); - functionContext = this.getFunctionContext(originalContent, originalLocation.line) ?? originalLocation.name; + // functionContext = this.getFunctionContext(originalContent, originalLocation.line) ?? originalLocation.name; } return Object.assign(stackFrame, { @@ -254,7 +254,7 @@ export default class JavascriptEventWorker extends EventWorker { * @param line - number of the line from the stack trace * @returns {string | null} - string of the function context or null if it could not be parsed */ - private getFunctionContext(sourceCode: string, line: number): string | null { + private _getFunctionContext(sourceCode: string, line: number): string | null { let functionName: string | null = null; let className: string | null = null; let isAsync = false; From 084fce2d06aa01d93628a588e6920d962bc49baa Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Tue, 2 Sep 2025 20:19:34 +0300 Subject: [PATCH 2/2] fix(): fix source-map saving (#449) * fix(): avoid mutations on savedFiles * revert js worker changes * fix(): js worker tests * imp(): catch errors on get function context --- workers/javascript/src/index.ts | 27 +++++++++++++++++---------- workers/release/src/index.ts | 29 ++++++++++++++--------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/workers/javascript/src/index.ts b/workers/javascript/src/index.ts index 7af09867..c2edda98 100644 --- a/workers/javascript/src/index.ts +++ b/workers/javascript/src/index.ts @@ -228,14 +228,20 @@ export default class JavascriptEventWorker extends EventWorker { * Fixes bug: https://github.com/codex-team/hawk.workers/issues/121 */ if (originalLocation.source) { - /** - * Get 5 lines above and 5 below - */ - lines = this.readSourceLines(consumer, originalLocation); + try { + /** + * Get 5 lines above and 5 below + */ + lines = this.readSourceLines(consumer, originalLocation); - const _originalContent = consumer.sourceContentFor(originalLocation.source); + const originalContent = consumer.sourceContentFor(originalLocation.source); - // functionContext = this.getFunctionContext(originalContent, originalLocation.line) ?? originalLocation.name; + functionContext = this.getFunctionContext(originalContent, originalLocation.line) ?? originalLocation.name; + } catch(e) { + HawkCatcher.send(e); + this.logger.error('Can\'t get function context'); + this.logger.error(e); + } } return Object.assign(stackFrame, { @@ -254,7 +260,7 @@ export default class JavascriptEventWorker extends EventWorker { * @param line - number of the line from the stack trace * @returns {string | null} - string of the function context or null if it could not be parsed */ - private _getFunctionContext(sourceCode: string, line: number): string | null { + private getFunctionContext(sourceCode: string, line: number): string | null { let functionName: string | null = null; let className: string | null = null; let isAsync = false; @@ -264,6 +270,7 @@ export default class JavascriptEventWorker extends EventWorker { const ast = parse(sourceCode, { sourceType: 'module', plugins: [ + 'jsx', 'typescript', 'classProperties', 'decorators', @@ -284,7 +291,7 @@ export default class JavascriptEventWorker extends EventWorker { ClassDeclaration(path) { if (path.node.loc && path.node.loc.start.line <= line && path.node.loc.end.line >= line) { console.log(`class declaration: loc: ${path.node.loc}, line: ${line}, node.start.line: ${path.node.loc.start.line}, node.end.line: ${path.node.loc.end.line}`); - + className = path.node.id.name || null; } }, @@ -297,7 +304,7 @@ export default class JavascriptEventWorker extends EventWorker { ClassMethod(path) { if (path.node.loc && path.node.loc.start.line <= line && path.node.loc.end.line >= line) { console.log(`class declaration: loc: ${path.node.loc}, line: ${line}, node.start.line: ${path.node.loc.start.line}, node.end.line: ${path.node.loc.end.line}`); - + // Handle different key types if (path.node.key.type === 'Identifier') { functionName = path.node.key.name; @@ -313,7 +320,7 @@ export default class JavascriptEventWorker extends EventWorker { FunctionDeclaration(path) { if (path.node.loc && path.node.loc.start.line <= line && path.node.loc.end.line >= line) { console.log(`function declaration: loc: ${path.node.loc}, line: ${line}, node.start.line: ${path.node.loc.start.line}, node.end.line: ${path.node.loc.end.line}`); - + functionName = path.node.id.name || null; isAsync = path.node.async; } diff --git a/workers/release/src/index.ts b/workers/release/src/index.ts index 68b004a0..3359dda7 100644 --- a/workers/release/src/index.ts +++ b/workers/release/src/index.ts @@ -162,7 +162,7 @@ export default class ReleaseWorker extends Worker { /** * Iterate all maps of the new release and save only new */ - let savedFiles = await Promise.all(files.map(async (map: SourceMapDataExtended) => { + const savedFiles = await Promise.all(files.map(async (map: SourceMapDataExtended) => { /** * Skip already saved maps */ @@ -181,30 +181,29 @@ export default class ReleaseWorker extends Worker { /** * Save id of saved file instead */ - map._id = fileInfo._id; - - return map; + return { + ...map, + _id: fileInfo._id, + }; } catch (error) { this.logger.error(`Map ${map.mapFileName} was not saved: ${error}`); } })); /** - * Delete file content after it is saved to the GridFS + * Filter undefined files and then prepare files that would be saved to releases table + * we do not need their content since it would be stored in gridFS */ - savedFiles.forEach(file => { - delete file.content; + const savedFilesWithoutContent: Omit[] = savedFiles.filter(file => { + return file !== undefined; + }).map(({ content, ...rest }) => { + return rest; }); - /** - * Filter unsaved maps - */ - savedFiles = savedFiles.filter((file) => file !== undefined); - /** * Nothing to save: maps was previously saved */ - if (savedFiles.length === 0) { + if (savedFilesWithoutContent.length === 0) { return; } @@ -218,7 +217,7 @@ export default class ReleaseWorker extends Worker { await this.releasesCollection.insertOne({ projectId: projectId, release: payload.release, - files: savedFiles as SourceMapDataExtended[], + files: savedFilesWithoutContent, } as ReleaseDBScheme, { session }); } @@ -228,7 +227,7 @@ export default class ReleaseWorker extends Worker { }, { $push: { files: { - $each: savedFiles as SourceMapDataExtended[], + $each: savedFilesWithoutContent, }, }, }, { session });