Skip to content

Commit 388b0da

Browse files
committed
fix: suggest deno v2 on failure to download
1 parent 45efd99 commit 388b0da

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

internal/functions/download/download.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package download
22

33
import (
4+
"bufio"
45
"bytes"
56
"context"
67
"fmt"
@@ -200,10 +201,40 @@ func extractOne(ctx context.Context, slug, eszipPath string) error {
200201
network.NetworkingConfig{},
201202
"",
202203
os.Stdout,
203-
os.Stderr,
204+
getErrorLogger(),
204205
)
205206
}
206207

208+
func getErrorLogger() io.Writer {
209+
if utils.Config.EdgeRuntime.DenoVersion > 1 {
210+
return os.Stderr
211+
}
212+
// Additional error handling for deno v1
213+
r, w := io.Pipe()
214+
go func() {
215+
logs := bufio.NewScanner(r)
216+
for logs.Scan() {
217+
line := logs.Text()
218+
fmt.Fprintln(os.Stderr, line)
219+
if strings.EqualFold(line, "invalid eszip v2") {
220+
utils.CmdSuggestion = suggestDenoV2()
221+
}
222+
}
223+
if err := logs.Err(); err != nil {
224+
fmt.Fprintln(os.Stderr, err)
225+
}
226+
}()
227+
return w
228+
}
229+
230+
func suggestDenoV2() string {
231+
return fmt.Sprintf(`Please use deno v2 in %s to download this Function:
232+
233+
[edge_runtime]
234+
deno_version = 2
235+
`, utils.Bold(utils.ConfigPath))
236+
}
237+
207238
func suggestLegacyBundle(slug string) string {
208239
return fmt.Sprintf("\nIf your function is deployed using CLI < 1.120.0, trying running %s instead.", utils.Aqua("supabase functions download --legacy-bundle "+slug))
209240
}

0 commit comments

Comments
 (0)