fix(45713) Improve error report summaries#45742
Conversation
|
@orta Code updated:
|
|
This is looking great! It looks feature complete to me? @typescript-bot pack this |
@orta Thank you! I am just thoughtful, imagine you had a file with 12 errors, I don't know how common it is, but it could push the table out by one space. Do you think it's an edge case worth handling, or will it likely not occur? |
|
Hey @orta, I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
|
No worries: for that you would push it in! It can go pretty high: But what if you have over 999,999 (a million!) errors in a single file? I think at that point it is ok to break the table Mainly because I don't really think that will ever happen 🥇 - kudos if this hits someone though |
|
@orta Code updated
|
|
Untagged WIP |
| tabularData += headerRow; | ||
| distinctFiles.forEach(file => { | ||
| const errorCountForFile = countWhere(filesInError, fileInError => fileInError!.fileName === file!.fileName); | ||
| const errorCountDigitsLength = Math.log(errorCountForFile) * Math.LOG10E + 1 | 0; |
There was a problem hiding this comment.
a less abstract alternative could be String(errorCountForFile).length (unless I'm missing something)
There was a problem hiding this comment.
@orta I agree that could also work. I'm happy to update it, it's probably easier to read. I just felt it was a little strange to convert to a string to get the length and nothing else.
| Diagnostics.Found_0_errors_in_1_file : | ||
| Diagnostics.Found_0_errors_in_1_files, | ||
| errorCount, | ||
| distinctFileNamesWithLines.length); |
There was a problem hiding this comment.
This is quite a dense statement, not sure I have any good ideas off the top off my head on how to improve it though
There was a problem hiding this comment.
I'll have a look back at it and see what I could do. I also try to avoid double ternaries if I can avoid it.
There was a problem hiding this comment.
What about something like this?
if(distinctFileNamesWithLines.length === 0 && errorCount !== 1) {
const foundErrorsWithNoFilesDiagnostic = createCompilerDiagnostic(
Diagnostics.Found_0_errors,
errorCount);
return `${newLine}${flattenDiagnosticMessageText(foundErrorsWithNoFilesDiagnostic.messageText, newLine)}${newLine}${newLine}`;
}
const d = errorCount === 1 ?
createCompilerDiagnostic(
filesInError[0] !== undefined ?
Diagnostics.Found_1_error_in_1 :
Diagnostics.Found_1_error,
errorCount,
distinctFileNamesWithLines[0]) :
createCompilerDiagnostic(
distinctFileNamesWithLines.length === 1 ?
Diagnostics.Found_0_errors_in_1_file :
Diagnostics.Found_0_errors_in_1_files,
errorCount,
distinctFileNamesWithLines.length);
return `${newLine}${flattenDiagnosticMessageText(d.messageText, newLine)}${newLine}${newLine}${errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles) : ""}${newLine}`;
There was a problem hiding this comment.
Works for me, wes also said this is pretty common in the codebase, so the original is also fine 👍🏻
| 1 /src/project/src/directUse.ts:2 | ||
| 1 /src/project/src/indirectUse.ts:2 | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated | ||
|
|
There was a problem hiding this comment.
In comparison to the original I think we might need an extra newline after the table to be consistent with our newlines 👍🏻
There was a problem hiding this comment.
Got it, I'll add an extra newline.
| const distinctFiles = filesInError.filter((value, index, self) => index === self.findIndex(file => file!.fileName === value!.fileName)); | ||
| if(distinctFiles.length === 0) return tabularData; | ||
|
|
||
| const headerRow = "Errors Files\n"; |
There was a problem hiding this comment.
This probably needs to be a localized message~
There was a problem hiding this comment.
If we do that, (which I think we probably do need to do) then the numbers about length etc will need to not be hardcoded anymore. For example the Chinese version of "errors" might be 1-2 characters characters wide.
There was a problem hiding this comment.
I didn't think of that, yes this should probably be localised.
If we do that, (which I think we probably do need to do) then the numbers about length etc will need to not be hardcoded anymore
May I ask how you mean by "hardcoded" here? Do you mean we don't need to bother so much about left padding?
There was a problem hiding this comment.
By hardcoding, I mean const BASE_LEFT_PADDING = 6; only makes sense when 'errors' the string is 6 characters long for example.
Armed with google translate, perhaps this is a reasonable design answer:
错误 案卷
3 build/lib/builtInExtensionsCG.ts
错误 案卷
12 build/lib/builtInExtensionsCG.ts
123 extensions/html-language-features/client/src/htmlClient.ts
错误 案卷
12 build/lib/builtInExtensionsCG.ts
123 extensions/html-language-features/client/src/htmlClient.ts
1234 extensions/html-language-features/client/src/htmlEmptyTagsShared.ts
Where tsc pulls out the longest length of a value from either the highest number of errors in a file or the translated word for "errors", allowing people to have a MAX_INT amount of errors because it just moves the column to the right once it hits a particular size
错误 案卷
12 build/lib/builtInExtensionsCG.ts
123 extensions/html-language-features/client/src/htmlClient.ts
1234 extensions/html-language-features/client/src/htmlEmptyTagsShared.ts
123456789 extensions/html-language-features/client/src/tagClosing.ts
Errors Files
12 build/lib/builtInExtensionsCG.ts
123 extensions/html-language-features/client/src/htmlClient.ts
1234 extensions/html-language-features/client/src/htmlEmptyTagsShared.ts
123456789 extensions/html-language-features/client/src/tagClosing.ts
Does that feel reasonable to you?
There was a problem hiding this comment.
That will work for me too. I'll work on it and see what I can come up with. Thank you for the explanation.
…e to localization
|
@orta Apologies for not getting back onto this, life got in the way. |
…ader due to localization - Fixed baseline error - Fixed linter error
|
Never feel guilty for not contributing to OSS in your spare time. I'm here to also help getting it in 👍🏻 |
|
OK, I think this is good to go 👍🏻 |
|
Thanks @rbargholz! |
* Improve error report summaries (microsoft#45713) * fixup! Improve error report summaries (microsoft#45713) * fixup! fixup! Improve error report summaries (microsoft#45713) * Adds support for handling localization renaming the 'files' header due to localization * fixup! Adds support for handling localization renaming the 'files' header due to localization - Fixed baseline error - Fixed linter error Co-authored-by: Orta <git@orta.io> Co-authored-by: Orta Therox <ortam@microsoft.com>

This PR intends to improve the error report summaries that get generated from diagnostics. Cases where there are multiple errors: "4 errors in 2 files" as well as single errors, "1 error in testA.ts:4" are accounted for as stated in the issue.
Fixes #45713