Skip to content

fix(prisma): stop migrate status panicking on a trailing migration id - #3836

Merged
KuSh merged 1 commit into
rtk-ai:developfrom
KuSh:fix/prisma-migrate-status-panic
Sep 11, 2026
Merged

KuSh merged 1 commit into
rtk-ai:developfrom
KuSh:fix/prisma-migrate-status-panic

Conversation

@KuSh

@KuSh KuSh commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Problem

filter_migrate_status (src/cmds/js/prisma_cmd.rs) finds the 202… migration id, looks for the whitespace that ends it, and falls back to a hardcoded 20 bytes when there is none:

let end = line[pos..].find(|c: char| c.is_whitespace()).unwrap_or(20);
latest_migration = line[pos..pos + end].to_string();

When the id runs to the end of the line there is no whitespace, so the slice runs past it:

Migration could not be applied at 2024-01-01T12:00:00
len 53, pos 34, end 20  ->  line[34..54]
thread panicked: end byte index 54 is out of bounds

Release builds set panic = "abort" (Cargo.toml), so rtk prisma migrate status dies outright and the user loses the command's output — the failure mode .claude/rules/rust-patterns.md singles out ("If filter fails, execute raw command unchanged. Never block the user").

A multibyte character straddling pos + 20 panics the same way, as a char-boundary error instead.

Fix

Fall back to the rest of the line, which is what the sibling filter_migrate_dev has always done 70 lines above:

let end = line[pos..]
    .find(|c: char| c.is_whitespace())
    .unwrap_or(line.len() - pos);

That bound is char-safe by construction: line.len() - pos is exactly the length of the line[pos..] slice.

Test plan

filter_migrate_status had no test at all (only test_filter_migrate_dev existed). Added one covering both shapes — an id at end of line, and a multibyte character right after it — and verified it panics at prisma_cmd.rs:320 with the old fallback restored, then passes with the fix.

cargo fmt --all && cargo clippy --all-targets && cargo test --all clean.

Found by a review round while working on another PR; unrelated to that work, so it is on its own branch off develop.

🤖 Generated with Claude Code

`filter_migrate_status` looked for whitespace after the `202...` id and fell
back to a hardcoded 20 bytes when there was none -- so an id that runs to the
end of the line slices past it:

    Migration could not be applied at 2024-01-01T12:00:00
    len 53, pos 34, end 20 -> line[34..54] -> end byte index 54 is out of bounds

Release builds set `panic = "abort"`, so `rtk prisma migrate status` dies and
the user loses the command output entirely -- the one thing a filter must never
do. A multibyte character straddling that offset panics the same way, on the
char boundary instead.

The fallback is the rest of the line, which is what the sibling
`filter_migrate_dev` has always used 70 lines above.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@aeppling aeppling left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@KuSh
KuSh merged commit fc19d7a into rtk-ai:develop Sep 11, 2026
11 of 12 checks passed
@KuSh
KuSh deleted the fix/prisma-migrate-status-panic branch September 11, 2026 18:10
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Sep 11, 2026
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