Skip to content
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

Panic while word-diffing #56

Open
mdruiter opened this issue Nov 23, 2022 · 3 comments
Open

Panic while word-diffing #56

mdruiter opened this issue Nov 23, 2022 · 3 comments

Comments

@mdruiter
Copy link

I get an exception, while comparing two simple files using csvdiff -o word-diff:

x,[-C-]{+A+}
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/aswinkarthik/csvdiff/cmd.(*Formatter).wordLevelDiffs(0xc0000f7ac0, 0xb1a638, 0x0, 0x0, 0xc000182000, 0x2, 0x2, 0xb1a638, 0x0, 0x0, ...)
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/formatter.go:242 +0x1338
github.com/aswinkarthik/csvdiff/cmd.(*Formatter).wordDiff(...)
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/formatter.go:216
github.com/aswinkarthik/csvdiff/cmd.(*Formatter).Format(0xc0000f7ac0, 0xb1a638, 0x0, 0x0, 0xc000182000, 0x2, 0x2, 0xb1a638, 0x0, 0x0, ...)
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/formatter.go:51 +0x504
github.com/aswinkarthik/csvdiff/cmd.runContext(0xc0000f0000, 0x884060, 0xc000010018, 0x884060, 0xc000010020, 0x0, 0x0)
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/root.go:108 +0x4c5
github.com/aswinkarthik/csvdiff/cmd.glob..func2(0xaf89c0, 0xc0000243c0, 0x2, 0x4, 0x0, 0x0)
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/root.go:87 +0x283
github.com/spf13/cobra.(*Command).execute(0xaf89c0, 0xc000012060, 0x4, 0x4, 0xaf89c0, 0xc000012060)
        /home/travis/gopath/pkg/mod/github.com/spf13/[email protected]/command.go:826 +0x460
github.com/spf13/cobra.(*Command).ExecuteC(0xaf89c0, 0xc00005cda0, 0xc000059f20, 0x43cb8a)
        /home/travis/gopath/pkg/mod/github.com/spf13/[email protected]/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
        /home/travis/gopath/pkg/mod/github.com/spf13/[email protected]/command.go:864
github.com/aswinkarthik/csvdiff/cmd.Execute()
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/root.go:115 +0x76
main.main()
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/main.go:29 +0x59

Interestingly enough, this even happens with two equal files, including the difference found ([-C-]{+A+}).
My example data, for both files:

x,A
x,B
x,C

I tested both DOS (CRLF) and UNIX (LF) line endings. I'm running version 1.4.0 in Ubuntu via WSL2.

@datatraveller1
Copy link

datatraveller1 commented Nov 13, 2023

You are using the first field (default: -p0) as primary key. The issue is that three times "x" isn't a unique primary key.

@mdruiter
Copy link
Author

Ah!
I still would not expect a crash.
Plus finding a difference where there is none is not helpful as default behavior...

@raiki61
Copy link

raiki61 commented Sep 11, 2024

Ah! I still would not expect a crash. Plus finding a difference where there is none is not helpful as default behavior...

The same thing happened to me too.
i agree with your opinion

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

No branches or pull requests

3 participants