Report unknown translation tables instead of panicking - #17
Open
bmesuere wants to merge 1 commit into
Open
Conversation
`umgap translate -t 99` panicked with "index out of bounds: the len is 23 but the index is 98". The lookup indexed TABLES[id - 1] before checking the bounds, so the UnknownTable error below it was unreachable for any id past the end of the array. `-t 0` panicked too, for a second reason: 0 - 1 underflows. Both cases now go through checked_sub and get, and report the unknown table like the numbers inside the range that have no table (7, 8, 17 to 20) already did. Swept the whole range: 1 to 6, 9 to 16 and 21 to 23 translate, everything else from 0 to 25 is refused, and nothing panics. The regression test fails against the old lookup and passes against this one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
umgap translate -t 99panics:The lookup did
TABLES[id - 1]before checking bounds, so theUnknownTableerror directly below it was unreachable for any id past the end of the array.-t 0panicked for a second reason:0 - 1underflows.Both now go through
checked_subandget, and report the unknown table the same way the in-range numbers with no table (7, 8, 17–20) already did.Verification
Swept the whole range 0–25:
Unknown table: NThat valid set is exactly NCBI's genetic code numbering, and it is unchanged from before — only the failure mode differs.
The regression test covers
0,24,99and1000000. I checked it fails against the old lookup (panics) and passes against the new one, rather than assuming it would. 39 tests pass, fmt clean.