Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/cli/src/legacy/commands/db/reset/reset.errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export class LegacyDbResetVersionFlagsError extends Data.TaggedError(
}> {}

/**
* `--version` is not a valid integer. Byte-matches Go's
* `failed to parse <v>: invalid version number` (`repair.go:24-29`).
* `--version` is not a valid integer. Byte-matches Go's bare
* `repair.ErrInvalidVersion` = `invalid version number`, returned unwrapped by
* `reset.Run` (`reset.go:35-36`) — the `failed to parse <v>:` wrapper is the
* `migration repair` path only (`repair.go:29`).
*/
export class LegacyDbResetInvalidVersionError extends Data.TaggedError(
"LegacyDbResetInvalidVersionError",
Expand Down
4 changes: 3 additions & 1 deletion apps/cli/src/legacy/commands/db/reset/reset.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ export const legacyDbReset = Effect.fn("legacy.db.reset")(function* (flags: Lega
if (Option.isSome(flags.version)) {
const v = flags.version.value;
if (!INTEGER_PATTERN.test(v)) {
// Go's reset.Run returns the bare repair.ErrInvalidVersion (reset.go:35-36);
// the `failed to parse <v>:` wrapper belongs to `migration repair` only.
return yield* Effect.fail(
new LegacyDbResetInvalidVersionError({
message: `failed to parse ${v}: invalid version number`,
message: "invalid version number",

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.

The message now byte-matches Go, but the condition still diverges from Go's strconv.Atoi in two edge cases, so this exact error isn't emitted in exactly the cases Go emits it:

  • int64 overflowAtoi == ParseInt(s, 10, 0), which rejects values outside the int64 range, so Go's db reset --version 99999999999999999999 fails with this bare invalid version number (reset.go:35-36). INTEGER_PATTERN (/^[+-]?\d+$/u, line 51) accepts it, so the TS path falls through to the glob check and reports glob supabase/migrations/…: file does not exist instead.
  • empty version — Go guards with len(version) > 0 (reset.go:34), so an empty --version skips validation entirely and proceeds; here Option.isSome + the regex turn it into this error.

There's already a shared exact-Atoi mirror for this: legacyParseMigrationVersion (src/legacy/shared/legacy-migration-timestamp.format.ts:64), which migration repair uses for this same validation (repair.handler.ts:186 — repair's tests even pin the 20-digit overflow case). Replacing the INTEGER_PATTERN.test(v) check with legacyParseMigrationVersion(v) === undefined (plus a v.length > 0 guard mirroring reset.go:34) would close both gaps and drop the duplicated regex.

Both divergences predate this PR, so a follow-up is fine if you'd rather keep this diff minimal — but since the ticket's goal is byte-parity on this exact error path, worth tracking.

}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,15 @@ describe("legacy db reset", () => {
version: Option.some("not-a-number"),
}).pipe(Effect.provide(layer), Effect.exit);
expect(Exit.isFailure(exit)).toBe(true);
if (Exit.isFailure(exit))
expect(JSON.stringify(exit.cause)).toContain("invalid version number");
if (Exit.isFailure(exit)) {
const failure = Cause.findErrorOption(exit.cause);
expect(Option.isSome(failure) && failure.value._tag).toBe(
"LegacyDbResetInvalidVersionError",
);
// Go's reset.Run returns the bare repair.ErrInvalidVersion (reset.go:35-36) —
// no `failed to parse <v>:` wrapper (that belongs to `migration repair`).
expect(Option.isSome(failure) && failure.value.message).toBe("invalid version number");
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ describe("legacy migration repair", () => {
expect(Option.isSome(failure) && failure.value._tag).toBe(
"LegacyMigrationInvalidVersionError",
);
// Guard: unlike `db reset` (bare `invalid version number`, reset.go:35-36),
// `migration repair` keeps Go's `failed to parse <v>:` wrapper (repair.go:29).
expect(Option.isSome(failure) && failure.value.message).toBe(
"failed to parse not-a-number: invalid version number",
);
}
}).pipe(Effect.provide(layer));
});
Expand Down
Loading