Skip to content

Report unknown translation tables instead of panicking - #17

Open
bmesuere wants to merge 1 commit into
feature/thiserrorfrom
fix/translate-unknown-table
Open

Report unknown translation tables instead of panicking#17
bmesuere wants to merge 1 commit into
feature/thiserrorfrom
fix/translate-unknown-table

Conversation

@bmesuere

@bmesuere bmesuere commented Aug 18, 2026

Copy link
Copy Markdown
Member

umgap translate -t 99 panics:

thread 'main' panicked at src/dna/translation.rs:181:9:
index out of bounds: the len is 23 but the index is 98

The lookup did TABLES[id - 1] before checking bounds, so the UnknownTable error directly below it was unreachable for any id past the end of the array.

-t 0 panicked for a second reason: 0 - 1 underflows.

Both now go through checked_sub and get, 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:

translate 1–6, 9–16, 21–23
refused with Unknown table: N 0, 7, 8, 17–20, 24, 25
panic none

That 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, 99 and 1000000. 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.

`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>
Copilot AI lite review requested due to automatic review settings August 18, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Successfully merging this pull request may close these issues.

2 participants