Skip to content

fix(45713) Improve error report summaries #45742

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

Merged
merged 6 commits into from
Dec 7, 2021

Conversation

rbargholz
Copy link
Contributor

@rbargholz rbargholz commented Sep 6, 2021

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

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 6, 2021
@ghost
Copy link

ghost commented Sep 6, 2021

CLA assistant check
All CLA requirements met.

@rbargholz rbargholz changed the title [WIP] Improve error report summaries (#45713) fix (45713)[WIP] Improve error report summaries Sep 6, 2021
@rbargholz rbargholz changed the title fix (45713)[WIP] Improve error report summaries fix(45713) [WIP] Improve error report summaries Sep 6, 2021
@orta orta self-assigned this Sep 6, 2021
@rbargholz
Copy link
Contributor Author

@orta Code updated:

  • Added tabular data output of files and their errors when there is more than one error.

@orta
Copy link
Contributor

orta commented Sep 13, 2021

This is looking great! It looks feature complete to me?

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 13, 2021

Heya @orta, I've started to run the tarball bundle task on this PR at 08906dd. You can monitor the build here.

@rbargholz
Copy link
Contributor Author

This is looking great! It looks feature complete to me?

@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?

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 13, 2021

Hey @orta, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/110389/artifacts?artifactName=tgz&fileId=B711E9590F88354A7E3B9EEFEB52F791FD1A7586247CB188AFB71F0A3B463FEB02&fileName=/typescript-4.5.0-insiders.20210913.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

@orta
Copy link
Contributor

orta commented Sep 13, 2021

No worries: for that you would push it in!

Errors   Files
     1   /src/project/src/indirectUse.ts:2
    12   /src/project/src/directUse.ts:2
   123   /src/project/src/indirectUse.ts:2

It can go pretty high:

Errors   Files
     1   /src/project/src/indirectUse.ts:2
    12   /src/project/src/directUse.ts:2
123456   /src/project/src/indirectUse.ts:2

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

Errors   Files
     1   /src/project/src/indirectUse.ts:2
    12   /src/project/src/directUse.ts:2
1000000   /src/project/src/indirectUse.ts:2

Mainly because I don't really think that will ever happen 🥇 - kudos if this hits someone though

@rbargholz
Copy link
Contributor Author

@orta Code updated

  • Fixed lint issues
  • Error numbers will now push in til it caps out at 6 digits, if someone has written code that has literally a MILLION errors, the table will be pushed out by one space.

@rbargholz rbargholz changed the title fix(45713) [WIP] Improve error report summaries fix(45713) Improve error report summaries Sep 14, 2021
@rbargholz
Copy link
Contributor Author

Untagged WIP

@orta orta requested review from sandersn and weswigham September 14, 2021 16:16
Copy link
Contributor

@orta orta left a comment

Choose a reason for hiding this comment

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

Great work, only a few ideas for discussion - don't worry about the rebase, I can handle all that post reviews 👍🏻

tabularData += headerRow;
distinctFiles.forEach(file => {
const errorCountForFile = countWhere(filesInError, fileInError => fileInError!.fileName === file!.fileName);
const errorCountDigitsLength = Math.log(errorCountForFile) * Math.LOG10E + 1 | 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

a less abstract alternative could be String(errorCountForFile).length (unless I'm missing something)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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);
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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}`;

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me, wes also said this is pretty common in the codebase, so the original is also fine 👍🏻


Errors Files
1 /src/project/src/directUse.ts:2
1 /src/project/src/indirectUse.ts:2
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated

Copy link
Contributor

Choose a reason for hiding this comment

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

In comparison to the original I think we might need an extra newline after the table to be consistent with our newlines 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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";
Copy link
Member

Choose a reason for hiding this comment

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

This probably needs to be a localized message~

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

@rbargholz rbargholz Sep 15, 2021

Choose a reason for hiding this comment

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

I didn't think of that, yes this should probably be localised.

@orta

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That will work for me too. I'll work on it and see what I can come up with. Thank you for the explanation.

@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 1, 2021
@orta
Copy link
Contributor

orta commented Oct 1, 2021

OK, now it can handle when the number of errors is greater than the length of the title too:

Screen Shot 2021-10-01 at 3 14 40 PM

I also left a note for localizers to try and make sure that message doesn't get mangled in localization in the JSON.

@rbargholz
Copy link
Contributor Author

@orta Apologies for not getting back onto this, life got in the way.

…ader due to localization

 - Fixed baseline error
 - Fixed linter error
@orta
Copy link
Contributor

orta commented Oct 2, 2021

Never feel guilty for not contributing to OSS in your spare time. I'm here to also help getting it in 👍🏻

@orta
Copy link
Contributor

orta commented Dec 7, 2021

OK, I think this is good to go 👍🏻

@orta orta merged commit 7a12909 into microsoft:main Dec 7, 2021
@orta
Copy link
Contributor

orta commented Dec 7, 2021

Thanks @rbargholz!

mprobst pushed a commit to mprobst/TypeScript that referenced this pull request Jan 10, 2022
* 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 <[email protected]>
Co-authored-by: Orta Therox <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[CLI DX] Improve the 'x errors' message in the CLI
4 participants