Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add complete error info to test:run failures #125

Merged
merged 7 commits into from
Jan 27, 2021
Merged

Conversation

AnanyaJha
Copy link
Contributor

@AnanyaJha AnanyaJha commented Jan 26, 2021

What does this PR do?

This PR adds stacktrace information and a diagnostic util to any test failure results
It also sets the default value to 0 for any "time" related fields in the test:run output.

What issues does this PR fix or reference?

#2892, #2890, @W-8790874@

Functionality Before

Screen Shot 2021-01-25 at 11 49 59 PM

Functionality After

Screen Shot 2021-01-25 at 11 51 33 PM

@AnanyaJha AnanyaJha requested a review from a team as a code owner January 26, 2021 05:50
@AnanyaJha AnanyaJha changed the title fix: add stacktrace info to test:run failures fix: add complete error info to test:run failures Jan 26, 2021
const stackTrace = syncRecord.stackTrace;
const lineIndex = stackTrace.indexOf('line');
const colIndex = stackTrace.indexOf('column');
const line = stackTrace.substring(lineIndex + 5, lineIndex + 6);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems easy to break if the stacktrace characters do not match the parsing you are doing, which would later cause some problems when casting them into a number. Why do we want to parse the stacktrace like this ?

Copy link
Contributor Author

@AnanyaJha AnanyaJha Jan 26, 2021

Choose a reason for hiding this comment

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

That's true, if the exception message doesn't contain 'line' or 'column' we would run into issues. I can update it to return a default value in the event that line/col info wasn't present

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not only that, if the number after line or column is more than one character we'll be parsing it incorrectly. That's why I want to know if we need to parse this info or can we just push what we get from the server all the way to the user. Can you provide a sample of what we get from the server/api ?

Copy link
Contributor Author

@AnanyaJha AnanyaJha Jan 26, 2021

Choose a reason for hiding this comment

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

I'm working on switching this to a regular expression that should address the number issue. The response from the server generally has an exception message: System.AssertException: Assertion Failed and a stacktrace Class.MyApexTriggerTest.testExceptionThing: line 14, column 1. I think these two provide enough information about the errors, so we could just push it all the way to the user - but I also wanted to create a diagnostic that could be used in VS Code to add info to the 'Problems' tab.

From what I can tell, we weren't utilizing the 'Problems' tab for test runs earlier because the cli command itself was building a "file map" of the files in the user's package directory. The filepath associated with the error was formatted for source links in VS Code and displayed in a separate table like this:
Screen Shot 2021-01-26 at 11 33 40 AM

If we don't want to parse the error/stacktrace that we get from the server at this point, then that's something we would need to do in VS Code so we can still provide the user with a source link to navigate to the issue. Alternatively, we parse & build the whole source link here in the library like the cli command was doing..... 🥴

public getAsyncDiagnostic(asyncRecord: ApexTestResultRecord): ApexDiagnostic {
const lineIndex = asyncRecord.StackTrace.indexOf('line');
const colIndex = asyncRecord.StackTrace.indexOf('column');
const line = asyncRecord.StackTrace.substring(lineIndex + 5, lineIndex + 6);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same parsing concern as with getSyncDiagnostic

@AnanyaJha AnanyaJha requested a review from lcampos January 26, 2021 23:10
};

const matches = asyncRecord.StackTrace.match(/(line (\d+), column (\d+))/);
if (matches && matches[2] && matches[3]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a scenario where we get line info but not column and vice versa ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I haven't run into that scenario, but I can separate the if statements just to be on the safe side

@AnanyaJha AnanyaJha merged commit 8af0f0d into develop Jan 27, 2021
@AnanyaJha AnanyaJha deleted the aj/errorInfo branch January 27, 2021 00:56
lcampos pushed a commit that referenced this pull request Feb 3, 2021
lcampos pushed a commit that referenced this pull request Feb 3, 2021
klewis-sfdc pushed a commit that referenced this pull request Oct 24, 2022
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.

2 participants