Skip to content

Conversation

@masaru-iritani
Copy link
Contributor

What

Wrap the panic message at the terminal width.

Why

Closes #140

How Tested

tparse output is wrapped at 80 characters when the terminal width is 80 characters.

$ echo $COLUMNS
80

$ go run . -file ./test.jsonl
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓                  
┃   PANIC  package: command-line-arguments • TestLongPanic   ┃                  
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛                  
panic: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in dui      
maximus, finibus arcu in, ornare justo. Nullam at velit ullamcorper, pulvinar   
lectus nec, volutpat sem. Aliquam lacus risus, porta nec erat quis, ornare      
egestas risus. Sed ut mi dignissim, molestie nisl ac, vehicula risus. Quisque   
pretium efficitur scelerisque. Aenean tincidunt erat et sollicitudin feugiat.   
Donec fermentum urna mollis molestie volutpat. In lacinia auctor enim auctor    
fringilla. Nunc id elit vitae magna consectetur finibus id et lacus. Nullam     
pharetra risus eu ipsum euismod gravida. [recovered]                            
    panic: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in dui  
maximus, finibus arcu in, ornare justo. Nullam at velit ullamcorper, pulvinar   
lectus nec, volutpat sem. Aliquam lacus risus, porta nec erat quis, ornare      
egestas risus. Sed ut mi dignissim, molestie nisl ac, vehicula risus. Quisque   
pretium efficitur scelerisque. Aenean tincidunt erat et sollicitudin feugiat.   
Donec fermentum urna mollis molestie volutpat. In lacinia auctor enim auctor    
fringilla. Nunc id elit vitae magna consectetur finibus id et lacus. Nullam     
pharetra risus eu ipsum euismod gravida.                                        
                                                                                
goroutine 21 [running]:                                                         
testing.tRunner.func1.2({0x629aa0, 0x6d5410})                                   
    /usr/local/go/src/testing/testing.go:1734 +0x21c                            
testing.tRunner.func1()                                                         
    /usr/local/go/src/testing/testing.go:1737 +0x35e                            
panic({0x629aa0?, 0x6d5410?})                                                   
    /usr/local/go/src/runtime/panic.go:792 +0x132                               
command-line-arguments.TestLongPanic(0xc00008efc0?)                             
    /workspaces/tparse/tests/panic_test.go:98 +0x26                             
testing.tRunner(0xc00008efc0, 0x691ae8)                                         
    /usr/local/go/src/testing/testing.go:1792 +0xf4                             
created by testing.(*T).Run in goroutine 1                                      
    /usr/local/go/src/testing/testing.go:1851 +0x413                            
FAIL    command-line-arguments    0.006s                                        
                                                                                
╭────────┬─────────┬────────────────────────┬───────┬──────┬──────┬──────╮
│ Status │ Elapsed │        Package         │ Cover │ Pass │ Fail │ Skip │
├────────┼─────────┼────────────────────────┼───────┼──────┼──────┼──────┤
│ PANIC  │  0.00s  │ command-line-arguments │  --   │  --  │  --  │  --  │
╰────────┴─────────┴────────────────────────┴───────┴──────┴──────┴──────╯
exit status 1

Ref

The latest version without this change outputs a lot of trailing spaces which result in a lot of blank lines.

$ go run github.com/mfridman/tparse@latest -file ./test.jsonl
go: downloading github.com/mfridman/tparse v0.17.0
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
┃   PANIC  package: command-line-arguments • TestLongPanic   ┃                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
panic: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in dui maximus, finibus arcu in, ornare justo. Nullam at velit ullamcorper, pulvinar lectus nec, volutpat sem. Aliquam lacus risus, porta nec erat quis, ornare egestas risus. Sed ut mi dignissim, molestie nisl ac, vehicula risus. Quisque pretium efficitur scelerisque. Aenean tincidunt erat et sollicitudin feugiat. Donec fermentum urna mollis molestie volutpat. In lacinia auctor enim auctor fringilla. Nunc id elit vitae magna consectetur finibus id et lacus. Nullam pharetra risus eu ipsum euismod gravida. [recovered]
        panic: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in dui maximus, finibus arcu in, ornare justo. Nullam at velit ullamcorper, pulvinar lectus nec, volutpat sem. Aliquam lacus risus, porta nec erat quis, ornare egestas risus. Sed ut mi dignissim, molestie nisl ac, vehicula risus. Quisque pretium efficitur scelerisque. Aenean tincidunt erat et sollicitudin feugiat. Donec fermentum urna mollis molestie volutpat. In lacinia auctor enim auctor fringilla. Nunc id elit vitae magna consectetur finibus id et lacus. Nullam pharetra risus eu ipsum euismod gravida.            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
goroutine 21 [running]:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
testing.tRunner.func1.2({0x629aa0, 0x6d5410})                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
        /usr/local/go/src/testing/testing.go:1734 +0x21c                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
testing.tRunner.func1()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
        /usr/local/go/src/testing/testing.go:1737 +0x35e                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
panic({0x629aa0?, 0x6d5410?})                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
        /usr/local/go/src/runtime/panic.go:792 +0x132                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
command-line-arguments.TestLongPanic(0xc00008efc0?)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
        /workspaces/tparse/tests/panic_test.go:98 +0x26                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
testing.tRunner(0xc00008efc0, 0x691ae8)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
        /usr/local/go/src/testing/testing.go:1792 +0xf4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
created by testing.(*T).Run in goroutine 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
        /usr/local/go/src/testing/testing.go:1851 +0x413                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
FAIL    command-line-arguments  0.006s                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
╭────────┬─────────┬────────────────────────┬───────┬──────┬──────┬──────╮
│ Status │ Elapsed │        Package         │ Cover │ Pass │ Fail │ Skip │
├────────┼─────────┼────────────────────────┼───────┼──────┼──────┼──────┤
│ PANIC  │  0.00s  │ command-line-arguments │  --   │  --  │  --  │  --  │
╰────────┴─────────┴────────────────────────┴───────┴──────┴──────┴──────╯
exit status 1

Comment on lines 118 to 121
width, _, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil {
width = 80
}
Copy link
Contributor Author

@masaru-iritani masaru-iritani Jun 4, 2025

Choose a reason for hiding this comment

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

96 is used for dividers. Should we use it here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried using the terminal width (with a fallback to 96) for both panic messages and dividers in 4ee4e5e

Comment on lines 3 to 12
import (
"fmt"
"os"
"sort"
"strings"

"github.com/charmbracelet/lipgloss"

"github.com/mfridman/tparse/parse"
"golang.org/x/term"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The classic blocks for ordering are

  • std lib
  • new line
  • external dependencies
  • new line
  • subpackages of current module

So here, it should be

 import ( 
          "fmt" 
          "os" 
          "sort" 
          "strings" 
 
          "github.com/charmbracelet/lipgloss" 
          "golang.org/x/term"

          "github.com/mfridman/tparse/parse" 
  )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by ce79ac6

@masaru-iritani masaru-iritani requested a review from ccoVeille June 6, 2025 10:30
go.mod Outdated
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/term v0.32.0 // indirect
Copy link
Owner

Choose a reason for hiding this comment

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

Run go mod tidy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by 8fe7ca3. Please let me know if you want me to squash commits.

@masaru-iritani masaru-iritani requested a review from mfridman June 12, 2025 00:12
Copy link
Owner

@mfridman mfridman left a comment

Choose a reason for hiding this comment

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

Thanks for the PR 🚀

@mfridman mfridman merged commit 254a920 into mfridman:main Jun 12, 2025
3 checks passed
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.

tparse outputs a lot of trailing spaces when tests panic with a long message

3 participants