Skip to content

fix(cli): handle AlreadyExists errors in directory creation#5724

Merged
avallete merged 1 commit into
developfrom
claude/derivative-sync-makedirectory-2l92dz
Jun 29, 2026
Merged

fix(cli): handle AlreadyExists errors in directory creation#5724
avallete merged 1 commit into
developfrom
claude/derivative-sync-makedirectory-2l92dz

Conversation

@avallete

Copy link
Copy Markdown
Member

Extract directory creation logic into a new legacyMakeDir utility that matches Go's os.MkdirAll behavior by treating an already-existing directory as success.

The Effect/Bun FileSystem.makeDirectory API can surface an AlreadyExists SystemError for existing directories on some platforms (notably Windows with OneDrive reparse points — CLI-1849), even with recursive: true. This differs from Go's os.MkdirAll, which returns nil when the target is already a directory.

Key changes:

  • Add legacyMakeDir utility in apps/cli/src/legacy/shared/legacy-make-dir.ts that wraps FileSystem.makeDirectory and recovers from AlreadyExists errors
  • Add comprehensive unit tests covering success case, AlreadyExists recovery, and error propagation
  • Replace three inline makeDirectory calls in db diff, db pull, and db schema declarative sync handlers with legacyMakeDir

This ensures the CLI's migration writers never fail on a pre-existing supabase/migrations directory, matching the original Go implementation's behavior.

https://claude.ai/code/session_01AWa8Hr8BS2pZucac9r3wb7

`db schema declarative sync` (and `db diff`/`db pull`) aborted with
`AlreadyExists: FileSystem.makeDirectory (...\supabase\migrations)` when
the migrations directory already existed. Go's `os.MkdirAll` returns nil
for an existing directory, but Effect's Bun `FileSystem.makeDirectory`
can surface an `AlreadyExists` SystemError even with `recursive: true` on
some platforms (notably Windows / OneDrive reparse-point dirs), which
regressed the command when it was ported to native TypeScript.

Add a shared `legacyMakeDir` helper that recovers from the `AlreadyExists`
reason so re-creating an existing directory is a no-op, matching
`os.MkdirAll`, and route the migration/output writers in sync, diff, and
pull through it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AWa8Hr8BS2pZucac9r3wb7
@avallete avallete requested a review from a team as a code owner June 29, 2026 10:05
@github-actions

Copy link
Copy Markdown

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@9f6a89b36a319ec7a2fc257a485be4a17533e424

Preview package for commit 9f6a89b.

@avallete avallete added this pull request to the merge queue Jun 29, 2026
Merged via the queue into develop with commit 8d2e6d6 Jun 29, 2026
19 checks passed
@avallete avallete deleted the claude/derivative-sync-makedirectory-2l92dz branch June 29, 2026 10:42
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.

3 participants