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
27 changes: 17 additions & 10 deletions workers/javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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;
Expand All @@ -264,6 +270,7 @@ export default class JavascriptEventWorker extends EventWorker {
const ast = parse(sourceCode, {
sourceType: 'module',
plugins: [
'jsx',
'typescript',
'classProperties',
'decorators',
Expand All @@ -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;
}
},
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
29 changes: 14 additions & 15 deletions workers/release/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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<SourceMapDataExtended, 'content'>[] = 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;
}

Expand All @@ -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 });
}

Expand All @@ -228,7 +227,7 @@ export default class ReleaseWorker extends Worker {
}, {
$push: {
files: {
$each: savedFiles as SourceMapDataExtended[],
$each: savedFilesWithoutContent,
},
},
}, { session });
Expand Down
Loading