Skip to content

gh pr diff error on long line #4633

@jjkinsey

Description

@jjkinsey

Describe the bug

Using pr diff on a PR that happened to include some very long lines (~139 kB, displays in the web viewer as "large diff" by default & does not render), I encountered a crash:

error reading pull request diff: bufio.Scanner: token too long

The output was correct (comparing with the web PR viewer) up to the first very long line.

Piping the output to an external program (e.g. less) averts the crash, but passing the --color always option brings it back.

Steps to reproduce the behavior

  1. Run gh pr diff providing a PR that includes a diff with very long lines
  2. See error
  3. Try e.g. gh pr diff --color never | less
  4. See no error
  5. Try e.g. gh pr diff --color always | less -R
  6. See error

Expected vs actual behavior

Either the long lines should be truncated, the diff should not be displayed (by default?), as in the web viewer, or the lines should be displayed in full. In any case, no error should be generated.

This looks like it's a result of using bufio.Scanner, which has a default buffer limit of 64 kB:

diffLines := bufio.NewScanner(diff)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority-3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions