enry: Slice out of range error
Calling to GetLanguage method, sometimes we receive this error:
panic: runtime error: slice bounds out of range goroutine 17 [running, locked to thread]: bytes.Count(0x7f627818c0d0, 0x4b, 0x0, 0x1c420038c20, 0x1, 0x20, 0x0) /home/travis/.gimme/versions/go1.8.linux.amd64/src/bytes/bytes.go:62 +0x21d gopkg.in/src-d/enry%2ev1.getHeaderAndFooter(0x7f627818c0d0, 0x4b, 0x0, 0x0, 0x0, 0x0) /home/travis/gopath/src/gopkg.in/src-d/enry.v1/common.go:161 +0x9d gopkg.in/src-d/enry%2ev1.GetLanguagesByModeline(0x7f627818f4a0, 0x0, 0x7f627818c0d0, 0x4b, 0x0, 0x7f62482e6c08, 0x0, 0x0, 0x0, 0x0, …) /home/travis/gopath/src/gopkg.in/src-d/enry.v1/common.go:142 +0x5c gopkg.in/src-d/enry%2ev1.GetLanguages(0x7f627818f4a0, 0x0, 0x7f627818c0d0, 0x4b, 0x0, 0x0, 0x0, 0x0) /home/travis/gopath/src/gopkg.in/src-d/enry.v1/common.go:126 +0x129 gopkg.in/src-d/enry%2ev1.GetLanguage(0x7f627818f4a0, 0x0, 0x7f627818c0d0, 0x4b, 0x0, 0x1c420038e48, 0x1c42001a500) /home/travis/gopath/src/gopkg.in/src-d/enry.v1/common.go:38 +0x55 main.GetLanguage(0x7f627818f4a0, 0x0, 0x7f627818c0d0, 0x4b, 0x0, 0x0, 0x0) /home/travis/build/src-d/enry/shared/enry.go:11 +0x55 main._cgoexpwrap_f7db11756761_GetLanguage(0x7f627818f4a0, 0x0, 0x7f627818c0d0, 0x4b, 0x0, 0x0, 0x0) command-line-arguments/_obj/_cgo_gotypes.go:58 +0x9a
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (9 by maintainers)
Enry already has a test with nil content, as you can see here. It’s for the general function
GetLanguage, butGetLanguagesByModelineis the first strategy to run, so it should raise a fail if any problem.Anyway, I added a couple of cases with
niland[]byte{}as content to the testTestGetLanguagesByModelineand they pass without problems.There is a weird thing, the function where the process is raising a panic (
bytes.Count) works well withnilor[]byte{]content, demonstration hereFor the moment, I couldn’t reproduce yet the panic in local.
Keep on it.