Skip to content

Conversation

@JonasBa
Copy link
Member

@JonasBa JonasBa commented Mar 17, 2023

Reorder the regexp so that we prioritize the one more likely to match. Also adds tests and covered an edge case where input like 'at myFunction (/path/to/file.js)'; would have undefined paths.

I have generated the tests with the help of chatgpt and manually checked all of them - it got a few of them wrong or was testing impossible cases, but it did find that one edge case apparently

Comment on lines +130 to +176
if (lineMatch) {
let object: string | undefined;
let method: string | undefined;
let functionName: string | undefined;
let typeName: string | undefined;
let methodName: string | undefined;

if (lineMatch[1]) {
functionName = lineMatch[1];
if (lineMatch[1]) {
functionName = lineMatch[1];

let methodStart = functionName.lastIndexOf('.');
if (functionName[methodStart - 1] === '.') {
methodStart--;
}
let methodStart = functionName.lastIndexOf('.');
if (functionName[methodStart - 1] === '.') {
methodStart--;
}

if (methodStart > 0) {
object = functionName.slice(0, methodStart);
method = functionName.slice(methodStart + 1);
const objectEnd = object.indexOf('.Module');
if (objectEnd > 0) {
functionName = functionName.slice(objectEnd + 1);
object = object.slice(0, objectEnd);
if (methodStart > 0) {
object = functionName.slice(0, methodStart);
method = functionName.slice(methodStart + 1);
const objectEnd = object.indexOf('.Module');
if (objectEnd > 0) {
functionName = functionName.slice(objectEnd + 1);
object = object.slice(0, objectEnd);
}
}
typeName = undefined;
}
typeName = undefined;
}

if (method) {
typeName = object;
methodName = method;
}
if (method) {
typeName = object;
methodName = method;
}

if (method === '<anonymous>') {
methodName = undefined;
functionName = undefined;
}

if (method === '<anonymous>') {
methodName = undefined;
functionName = undefined;
if (functionName === undefined) {
methodName = methodName || '<anonymous>';
functionName = typeName ? `${typeName}.${methodName}` : methodName;
}

let filename = lineMatch[2] && lineMatch[2].startsWith('file://') ? lineMatch[2].slice(7) : lineMatch[2];
const isNative = lineMatch[5] === 'native';

if (!filename && lineMatch[5] && !isNative) {
filename = lineMatch[5];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an indentation change and order of operations is different - we first run the FULL_MATCH regexp which we expect to match most often and then the fallback

@AbhiPrasad AbhiPrasad merged commit b6f03bf into develop Mar 20, 2023
@AbhiPrasad AbhiPrasad deleted the jb/ref/stacktrace branch March 20, 2023 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants