Skip to content

Remove redundant progress text from Git error messages - #9945

Merged
rafeca merged 32 commits into
developmentfrom
your-carriage-awaits
Jun 11, 2020
Merged

rafeca merged 32 commits into
developmentfrom
your-carriage-awaits

Conversation

@niik

@niik niik commented Jun 5, 2020 •

Copy link
Copy Markdown
Member

🌵 This depends on #9944, please review that first 🌵

Description

When looking at #9944 I was struck once again by how bad our error messages from Git commands that show some sort of progress are:

image

While somewhat improved in #8964...

image

There's still a whole lot of redundant text in there that users don't care about and which often times ends up making it really hard to find the actual error message.

The reason for all of this is that Git (and many other CLI tools) leverage an old trick from the typewriter era called the carriage return character to make it seem like they're just updating a single character in the users' terminal.

giphy

When the users sees something like Progress: 1% that then changes to Progress: 2% what Git actually does is it writes Progress: 1% followed by a carriage return character (\r) which sends the "carriage" back to the leftmost position and then it overwrites the existing text with Progress: 2%. Since we didn't handle carriage returns we got, and displayed each of those updates which for clones and fetches of large repositories could be enormous.

This PR changes that by introducing a parser that emulates how a terminal would interpret carriage returns so now we only show the last progress line for each type of progress reported.

Screenshots

Before

Screen Shot 2020-06-05 at 13 06 29

After

image

Release notes

Notes: [Improved] Removed redundant progress text in Git error messages

@rafeca rafeca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can't express how much I ❤️ this PR! I've stumbled across clone errors that display all the percentage lines and the experience was quite bad. This will help users a lot!

Just added a few comments, nothing major

Comment thread app/src/lib/parse-carriage-return.ts Resolved
Comment thread app/src/lib/parse-carriage-return.ts Resolved
Comment thread app/src/ui/app-error.tsx Resolved
@niik
niik requested a review from rafeca June 9, 2020 09:36
Base automatically changed from retry-action-in-app-error to development June 9, 2020 09:37
rafeca
rafeca previously approved these changes Jun 9, 2020
niik added 2 commits June 11, 2020 13:34
Unless we decide to support the backspace character at some point I don't believe we ever have to care about the head of the existing line, it's all about whether there's anything remaining after we've applied the new text or not
This is the most common scenario in Git, they add white space up to the max line length they expect in order to ensure they erase the previous lines
@niik

niik commented Jun 11, 2020

Copy link
Copy Markdown
Member Author

@rafeca I realized when looking at the code with a fresh set of eyes that the ${before} part of our line merging wasn't necessary, it was alway an empty string which makes sense since the \r character always moves the cursor to the first column. That let me get rid of the col var and one unnecessary substring call.

I also spotted one more opportunity for optimization to avoid the last substring in the majority use case and I took the time to add a few more tests to validate these assumptions and to test both the happy path and the non-happy-path. Sorry for the extra review request!

@niik
niik requested a review from rafeca June 11, 2020 12:30
@rafeca

rafeca commented Jun 11, 2020

Copy link
Copy Markdown
Contributor

Thanks for doing these optimizations! From your explanations and by looking at the code they make sense.

I'm getting a little bit worried that using a RegExp makes the logic of this method a bit hard to understand due to a couple of smart tricks (overriding the lastIndex property and the RegExp definition with [\s\S] and the lazy matches). The comments that you added are really great and help a lot, but it still took me a bit to understand what's going on.

Have you considered just splitting the string manually to avoid using a RegExp? It will be less memory efficient but I don't think it would be a big deal in this scenario since we already have the whole string in memory... I'm thinking about something similar to:

  const lines = text.split('\n')

  const cleanLines = lines
    .map(line => {
      const sublines = line.split('\r')
      let out = ''

      for (const subline of sublines) {
        if (subline.length >= out.length) {
          // Happy path, the new line is equal to or longer
          // than the previous, we can just use the new one
          // without creating any new strings.
          out = subline
        } else {
          const remainder = out.substring(subline.length)
          out = `${subline}${remainder}`
        }
      }

      return out
    })

    return cleanLines.join('\n')

Comment thread app/src/lib/parse-carriage-return.ts Resolved
Comment thread app/src/lib/parse-carriage-return.ts Resolved
@niik

niik commented Jun 11, 2020

Copy link
Copy Markdown
Member Author

Have you considered just splitting the string manually to avoid using a RegExp? It will be less memory efficient but I don't think it would be a big deal in this scenario since we already have the whole string in memory... I'm thinking about something similar to:

Yes, I played around with something similar to that early on but I wasn't feeling great about all the intermediate arrays but I agree that this solution has incrementally evolved into something much more complex than I had originally envisioned.

While there are cases when the clone output become ridiculously long we do have a cap at 10Mb in dugite for stderr so even if the split/map approach would consume more peak memory (not saying it does, I haven't measured and substrings are usually cheap in v8) it should be at a cost we'd be willing to pay for less complexity.

I took your proposed change and tweaked it just a little bit since I think a reduce operation fits in really nicely here.

@niik
niik requested a review from rafeca June 11, 2020 14:21
expect(parseCarriageReturn('foo\r\r\r\r\rbar')).toBe('bar')
})

it('treats unicode line separator and paragraph separator as flow text', () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@rafeca This test is kinda pointless now that we're not using a regex but I think it's a fair test still in case we alter course in the future and turn it into a regex again. I'll drop it if you want though

@rafeca rafeca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!!! Let's merge this one 🚢

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