Skip to content

Commit e9e2a72

Browse files
authored
fix bot crash: pin Deno to v2.7.14 and use defineProperty for serve monkey-patch (#412)
Deno 2.8.0 converted Deno.serve into a lazy getter with no setter, so server.ts's `(Deno as any).serve = stub` assignment now throws "Cannot set property serve … which has only a getter" and the bot container fails to start. - Pin Deno to v2.7.14 in Dockerfile.bot (last 2.7.x, pre-getter) - Replace plain assignment with Object.defineProperty in server.ts, which bypasses the getter and survives a future bump to 2.8.x
1 parent 2bdb34e commit e9e2a72

2 files changed

Lines changed: 37 additions & 24 deletions

File tree

deployment/Dockerfile.bot

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ ENV PCC_LOG_FEATURES_SUMMARY=true
1111

1212
ENV PYTHONPATH=/app
1313

14-
# Install Deno for running edge functions locally
14+
# Install Deno for running edge functions locally.
15+
# Pinned: Deno 2.8.0 made Deno.serve a lazy getter, breaking the
16+
# monkey-patch in edge-functions/server.ts. Stay on the last 2.7.x.
1517
ENV DENO_INSTALL=/root/.deno
18+
ENV DENO_VERSION=v2.7.14
1619
RUN apt-get update && apt-get install -y --no-install-recommends curl unzip git \
17-
&& curl -fsSL https://deno.land/install.sh | sh \
20+
&& curl -fsSL https://deno.land/install.sh | sh -s "${DENO_VERSION}" \
1821
&& apt-get purge -y curl unzip && apt-get autoremove -y \
1922
&& rm -rf /var/lib/apt/lists/*
2023
ENV PATH="${DENO_INSTALL}/bin:${PATH}"

deployment/supabase/functions/server.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,32 @@ let currentFunctionName = "";
4141
// Save the real Deno.serve so we can restore it later
4242
const realServe = Deno.serve.bind(Deno);
4343

44-
// Replace Deno.serve with a stub that captures the handler
45-
// deno-lint-ignore no-explicit-any
46-
(Deno as any).serve = (handlerOrOpts: any, maybeHandler?: any) => {
47-
const fn: Handler | undefined =
48-
typeof handlerOrOpts === "function" ? handlerOrOpts : maybeHandler;
49-
if (currentFunctionName && fn) {
50-
routes[currentFunctionName] = fn;
51-
}
52-
// Return a fake Deno.HttpServer to satisfy any callers
53-
return {
54-
finished: Promise.resolve(),
55-
ref() {},
56-
unref() {},
57-
shutdown() {
58-
return Promise.resolve();
59-
},
60-
addr: { port: 0, hostname: "localhost", transport: "tcp" as const },
61-
};
62-
};
44+
// Replace Deno.serve with a stub that captures the handler.
45+
// Deno 2.8+ defines Deno.serve as a lazy getter with no setter, so plain
46+
// assignment throws "Cannot set property serve … which has only a getter".
47+
// defineProperty bypasses the getter because the property is configurable.
48+
Object.defineProperty(Deno, "serve", {
49+
// deno-lint-ignore no-explicit-any
50+
value: (handlerOrOpts: any, maybeHandler?: any) => {
51+
const fn: Handler | undefined =
52+
typeof handlerOrOpts === "function" ? handlerOrOpts : maybeHandler;
53+
if (currentFunctionName && fn) {
54+
routes[currentFunctionName] = fn;
55+
}
56+
// Return a fake Deno.HttpServer to satisfy any callers
57+
return {
58+
finished: Promise.resolve(),
59+
ref() {},
60+
unref() {},
61+
shutdown() {
62+
return Promise.resolve();
63+
},
64+
addr: { port: 0, hostname: "localhost", transport: "tcp" as const },
65+
};
66+
},
67+
configurable: true,
68+
writable: true,
69+
});
6370

6471
// Dynamically import each edge function — Deno.serve inside each module
6572
// will call our stub, populating `routes`.
@@ -73,9 +80,12 @@ for (const name of functionNames) {
7380
}
7481
currentFunctionName = "";
7582

76-
// Restore the real Deno.serve
77-
// deno-lint-ignore no-explicit-any
78-
(Deno as any).serve = realServe;
83+
// Restore the real Deno.serve (see defineProperty note above)
84+
Object.defineProperty(Deno, "serve", {
85+
value: realServe,
86+
configurable: true,
87+
writable: true,
88+
});
7989

8090
const loadedCount = Object.keys(routes).length;
8191
console.log(

0 commit comments

Comments
 (0)