supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
1.08k stars 209 forks source link

Deploy error 'Is a directory (os error 21)' occurs when special char in project path #2897

Open rpock opened 2 days ago

rpock commented 2 days ago

Describe the bug The Supabase CLI fails to deploy Edge Functions when the project path contains special characters (#). The error message suggests a directory issue, but the actual problem is the special characters in the path.

To Reproduce Steps to reproduce the behavior:

  1. Create a project directory containing special characters (e.g., /Users/username/Documents/#project/#app/)
  2. Initialize a Supabase project in this directory
  3. Create an Edge Function: supabase functions new my-function
  4. Create a simple Edge Function in index.ts
  5. Try to deploy using: supabase functions deploy my-function --project-ref [your-project-ref]
  6. Observe the deployment error

Expected behavior Either:

Screenshots Error output:

image

Error output searchable:

supabase functions deploy [my-function] --no-verify-jwt --project-ref [my-project-ref]
Bundling Function: [my-function]
Error 'Is a directory (os error 21)' contains boxed error of unknown type:
  Os { code: 21, kind: IsADirectory, message: "Is a directory" }
Error: failed to create the graph

Caused by:
    Is a directory (os error 21)
error running container: exit 1
Try rerunning the command with --debug to troubleshoot the error.

System information

avallete commented 1 day ago

I can confirm I've been able to reproduce, but with only two specials chars so far: # and ?, but other specials characters such as $ or % work well. Which lead me to think there is something on with shell path escaping.

The binding to the container that run the edge-runtime for bundling seems correct so the issue might actually come from the path normalization within the container bundling logic. I'm suspecting that maybe this is where things goes wrong: https://github.com/supabase/edge-runtime/blob/main/crates/sb_core/util/fs.rs#L208

Digging in, I've added debug logs to the edge-runtime and can confirm this is a bug with some "url" characters within deno path utils, I've setup a branch with some debug logs locally: https://github.com/supabase/edge-runtime/commit/26c55e40d24919a778ad18605528fee61a96233d#diff-d8f56ede5ccc2924ccf7a18b57eb0e3867fc7804abbb922021bac99e64355d1b

And the actual issue arise within the fetch_local function, this is the kind of debug output I got:

WARN: no seed files matched pattern: supabase/seed.sql
Bundling Function: my-function
DEBUG Opening cache /root/.cache/deno/dep_analysis_cache_v1...
DEBUG Opening cache /root/.cache/deno/node_analysis_cache_v1...
DEBUG Starting fetch_no_follow_with_options
DEBUG Input specifier: file:///Users/avallete/Programming/Supa/#cli/supabase/functions/my-function/index.ts
DEBUG Validating scheme
DEBUG Scheme is: file
DEBUG Checking permissions
DEBUG Permissions check passed
DEBUG Checking memory cache
DEBUG Not found in memory cache
DEBUG Handling file:// URL
DEBUG Starting fetch_local
DEBUG Input specifier: file:///Users/avallete/Programming/Supa/#cli/supabase/functions/my-function/index.ts
DEBUG Converting specifier to file path
DEBUG File path: "/Users/avallete/Programming/Supa/" <--- here we loose our proper path after to_file_path() is called
DEBUG Reading file bytes
DEBUG Failed to read file: Is a directory (os error 21)
Error 'Is a directory (os error 21)' contains boxed error of unknown type:
  Os { code: 21, kind: IsADirectory, message: "Is a directory" }
Error: failed to create the graph

Caused by:
    Is a directory (os error 21)
error running container: exit 1
Try rerunning the command with --debug to troubleshoot the error.
exit status 1