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

go: return a bad magic error in check when parsing summary #1206

Merged
merged 2 commits into from
Jul 31, 2024

Conversation

james-rms
Copy link
Collaborator

@james-rms james-rms commented Jul 31, 2024

Changelog

  • Changed: when attempting to read a corrupt MCAP using using the index, the reader will return an ErrBadMagic instance rather than a bare Error.

Docs

None.

Description

it's useful to be able to tell this error apart from errors that might result from i/o, but right now there is no simple way to determine this using errors.Is. This PR gives the error a publicly known type, so that callers can check for it.

BeforeAfter

@james-rms james-rms merged commit 71c5aa3 into main Jul 31, 2024
23 checks passed
@james-rms james-rms deleted the jrms/go-bad-magic-indexed-iterator branch July 31, 2024 21:49
@@ -83,7 +83,7 @@ func (it *indexedMessageIterator) parseSummarySection() error {
}
magic := buf[20:]
if !bytes.Equal(magic, Magic) {
return fmt.Errorf("not an MCAP file")
return &ErrBadMagic{location: magicLocationEnd, actual: magic}
Copy link

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants