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

Library terminates caller on error due to log.Fatalf #18

Open
its-luca opened this issue Aug 3, 2022 · 0 comments
Open

Library terminates caller on error due to log.Fatalf #18

its-luca opened this issue Aug 3, 2022 · 0 comments

Comments

@its-luca
Copy link
Contributor

its-luca commented Aug 3, 2022

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

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

1 participant