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 });