bibtex
bibtex copied to clipboard
Library terminates caller on error due to log.Fatalf
In the attached snippet from bibtex.go:274 log.Fatalf is called to handle an undefined situation.
This gives the caller no chance to recover. I think this should be at least replaced with a panic instead.
Ideally, we could get some more robust error handling that i.e. returns invalid entries.
I tried to look into implementing this but failed to go generate bibtex.y.go using modernc.org/goyacc.
Is this the tool you used for generation?
// GetStringVar looks up a string by its key.
func (bib *BibTex) GetStringVar(key string) *BibVar {
if bv, ok := bib.StringVar[key]; ok {
return bv
}
if v, ok := bib.getDefaultVar(key); ok {
return v
}
// This is undefined.
log.Fatalf("%s: %s", ErrUnknownStringVar, key)
return nil
}
Example triggering the log.Fatalf. (I know that this is invalid bibtex)
@misc{inteSDM,
title={a},
author={b},
year={2019},
month = May
}
Error message from go generate
panic: strings: negative Repeat count
goroutine 1 [running]:
strings.Repeat({0x102c51a20?, 0x16d2e798a?}, 0x1b?)
/usr/local/go/src/strings/strings.go:533 +0x3a0
main.main1({0x16d2e79a0, 0x8})
/Users/luca/go/pkg/mod/modernc.org/[email protected]/main.go:385 +0x294c
main.main()
/Users/luca/go/pkg/mod/modernc.org/[email protected]/main.go:180 +0x110
lexer.go:1: running "goyacc": exit status 2