-
Notifications
You must be signed in to change notification settings - Fork 23
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
Mz/error handling #355
Open
mingxuanzhangsfdx
wants to merge
7
commits into
main
Choose a base branch
from
mz/error-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mz/error handling #355
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ff776dc
chore: add error handling in the bottlenecks
mingxuanzhangsfdx 6dd4ce5
chore: catch exception in runAsyncTest workflow
mingxuanzhangsfdx 6f60eb9
chore: polish error handling
mingxuanzhangsfdx f3c10e6
chore: remove unnecessary catches
mingxuanzhangsfdx 4b35861
chore: add unit tests and change scope for tested methods
mingxuanzhangsfdx f069842
chore: stub fs.createWriteStream
mingxuanzhangsfdx b0b55ff
chore: delete hello
mingxuanzhangsfdx File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import * as util from 'util'; | |
import { calculatePercentage, queryAll } from './utils'; | ||
import { QUERY_RECORD_LIMIT } from './constants'; | ||
import { elapsedTime } from '../utils/elapsedTime'; | ||
import { nls } from '../i18n'; | ||
|
||
export class CodeCoverage { | ||
public readonly connection: Connection; | ||
|
@@ -54,43 +55,60 @@ export class CodeCoverage { | |
if (apexTestClassSet.size === 0) { | ||
return new Map(); | ||
} | ||
|
||
const perClassCodeCovResults = | ||
await this.queryPerClassCodeCov(apexTestClassSet); | ||
let perClassCodeCovResults; | ||
try { | ||
perClassCodeCovResults = | ||
await this.queryPerClassCodeCov(apexTestClassSet); | ||
} catch (error) { | ||
throw new Error( | ||
nls.localize('largeTestResultErr', [ | ||
'ApexCodeCoverage[]', | ||
error?.message | ||
]) | ||
); | ||
} | ||
|
||
const perClassCoverageMap = new Map<string, PerClassCoverage[]>(); | ||
|
||
perClassCodeCovResults.forEach((chunk) => { | ||
chunk.records.forEach((item) => { | ||
const totalLines = item.NumLinesCovered + item.NumLinesUncovered; | ||
const percentage = calculatePercentage( | ||
item.NumLinesCovered, | ||
totalLines | ||
); | ||
|
||
const value = { | ||
apexClassOrTriggerName: item.ApexClassOrTrigger.Name, | ||
apexClassOrTriggerId: item.ApexClassOrTrigger.Id, | ||
apexTestClassId: item.ApexTestClassId, | ||
apexTestMethodName: item.TestMethodName, | ||
numLinesCovered: item.NumLinesCovered, | ||
numLinesUncovered: item.NumLinesUncovered, | ||
percentage, | ||
...(item.Coverage ? { coverage: item.Coverage } : {}) | ||
}; | ||
const key = `${item.ApexTestClassId}-${item.TestMethodName}`; | ||
if (perClassCoverageMap.get(key)) { | ||
perClassCoverageMap.get(key).push(value); | ||
} else { | ||
perClassCoverageMap.set( | ||
`${item.ApexTestClassId}-${item.TestMethodName}`, | ||
[value] | ||
try { | ||
perClassCodeCovResults.forEach((chunk) => { | ||
chunk.records.forEach((item) => { | ||
const totalLines = item.NumLinesCovered + item.NumLinesUncovered; | ||
const percentage = calculatePercentage( | ||
item.NumLinesCovered, | ||
totalLines | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
return perClassCoverageMap; | ||
const value = { | ||
apexClassOrTriggerName: item.ApexClassOrTrigger.Name, | ||
apexClassOrTriggerId: item.ApexClassOrTrigger.Id, | ||
apexTestClassId: item.ApexTestClassId, | ||
apexTestMethodName: item.TestMethodName, | ||
numLinesCovered: item.NumLinesCovered, | ||
numLinesUncovered: item.NumLinesUncovered, | ||
percentage, | ||
...(item.Coverage ? { coverage: item.Coverage } : {}) | ||
}; | ||
const key = `${item.ApexTestClassId}-${item.TestMethodName}`; | ||
if (perClassCoverageMap.get(key)) { | ||
perClassCoverageMap.get(key).push(value); | ||
} else { | ||
perClassCoverageMap.set( | ||
`${item.ApexTestClassId}-${item.TestMethodName}`, | ||
[value] | ||
); | ||
} | ||
}); | ||
}); | ||
return perClassCoverageMap; | ||
} catch (error) { | ||
throw new Error( | ||
nls.localize('largeTestResultErr', [ | ||
'Map<string, PerClassCoverage[]>', | ||
error?.message | ||
]) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -107,9 +125,17 @@ export class CodeCoverage { | |
if (apexClassIdSet.size === 0) { | ||
return { codeCoverageResults: [], totalLines: 0, coveredLines: 0 }; | ||
} | ||
|
||
const codeCoverageAggregates = | ||
await this.queryAggregateCodeCov(apexClassIdSet); | ||
let codeCoverageAggregates; | ||
try { | ||
codeCoverageAggregates = await this.queryAggregateCodeCov(apexClassIdSet); | ||
} catch (error) { | ||
throw new Error( | ||
nls.localize('largeTestResultErr', [ | ||
'ApexCodeCoverageAggregate[]', | ||
error?.message | ||
]) | ||
); | ||
} | ||
|
||
let totalLinesCovered = 0; | ||
let totalLinesUncovered = 0; | ||
|
@@ -153,7 +179,7 @@ export class CodeCoverage { | |
} | ||
|
||
@elapsedTime() | ||
private async queryPerClassCodeCov( | ||
public async queryPerClassCodeCov( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What change to public? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the function is stubbed here in the unit test in order to mock the exception. |
||
apexTestClassSet: Set<string> | ||
): Promise<ApexCodeCoverage[]> { | ||
const perClassCodeCovQuery = | ||
|
@@ -162,7 +188,7 @@ export class CodeCoverage { | |
} | ||
|
||
@elapsedTime() | ||
private async queryAggregateCodeCov( | ||
public async queryAggregateCodeCov( | ||
apexClassIdSet: Set<string> | ||
): Promise<ApexCodeCoverageAggregate[]> { | ||
const codeCoverageQuery = | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mingxuanzhangsfdx a couple of issues I see with the strategy of adding try catch on queries.
First, assuming all errors thrown by the query are due to out of memory exception will present the user will a false cause. Maybe the user's network fails some how causing a network exception or some other unexpected issue.
Second, out of memory errors cannot be handled by any means.
Please research approaches to dealing with out of heap space errors and then we can talk about what can be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with Pete. A not so very good approach is to look for specific message in the returned error message but it is ver brittle and can break if the underlying error message returned changes