Skip to content

Commit 9e4cd16

Browse files
make sure that remote binding errors are surfaced when using mixed (hybrid) mode (#9515)
1 parent 1914b87 commit 9e4cd16

File tree

4 files changed

+84
-3
lines changed

4 files changed

+84
-3
lines changed

.changeset/pink-ties-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
make sure that remote binding errors are surfaced when using mixed (hybrid) mode

packages/wrangler/e2e/dev-mixed-mode.test.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { resolve } from "node:path";
33
import { setTimeout } from "node:timers/promises";
44
import getPort from "get-port";
55
import dedent from "ts-dedent";
6-
import { afterAll, beforeAll, describe, expect, it } from "vitest";
6+
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
77
import { WranglerE2ETestHelper } from "./helpers/e2e-wrangler-test";
88
import { fetchText } from "./helpers/fetch-text";
99
import { generateResourceName } from "./helpers/generate-resource-name";
@@ -194,6 +194,66 @@ describe("wrangler dev - mixed mode", () => {
194194
`);
195195
});
196196

197+
describe("shows helpful error logs", () => {
198+
it("when a remote service binding is not properly configured", async () => {
199+
await helper.seed({
200+
"wrangler.json": JSON.stringify({
201+
name: "mixed-mode-mixed-bindings-test",
202+
main: "simple-service-binding.js",
203+
compatibility_date: "2025-05-07",
204+
services: [
205+
{
206+
binding: "REMOTE_WORKER",
207+
service: "non-existent-service-binding",
208+
remote: true,
209+
},
210+
],
211+
}),
212+
});
213+
214+
const worker = helper.runLongLived("wrangler dev --x-mixed-mode");
215+
216+
await worker.waitForReady();
217+
218+
await vi.waitFor(
219+
() =>
220+
expect(worker.currentOutput).toContain(
221+
"Could not resolve service binding 'REMOTE_WORKER'. Target script 'non-existent-service-binding' not found."
222+
),
223+
5_000
224+
);
225+
});
226+
227+
it("when a remote KV binding is not properly configured", async () => {
228+
await helper.seed({
229+
"wrangler.json": JSON.stringify({
230+
name: "mixed-mode-mixed-bindings-test",
231+
main: "kv.js",
232+
compatibility_date: "2025-05-07",
233+
kv_namespaces: [
234+
{
235+
binding: "KV_BINDING",
236+
id: "non-existent-kv",
237+
remote: true,
238+
},
239+
],
240+
}),
241+
});
242+
243+
const worker = helper.runLongLived("wrangler dev --x-mixed-mode");
244+
245+
await worker.waitForReady();
246+
247+
await vi.waitFor(
248+
() =>
249+
expect(worker.currentOutput).toContain(
250+
"KV namespace 'non-existent-kv' is not valid."
251+
),
252+
5_000
253+
);
254+
});
255+
});
256+
197257
describe("multi-worker", () => {
198258
it("handles both remote and local service bindings at the same time in all workers", async () => {
199259
await helper.seed({

packages/wrangler/src/api/mixedMode/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function startMixedModeSession(
5454
inspector: {
5555
port: await getPort(),
5656
},
57-
logLevel: "none",
57+
logLevel: "error",
5858
},
5959
bindings: rawBindings,
6060
});

packages/wrangler/src/logger.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ overrideLoggerLevel.getStore;
6868

6969
export type TableRow<Keys extends string> = Record<Keys, string>;
7070

71+
function consoleMethodToLoggerLevel(
72+
method: Exclude<keyof Console, "Console">
73+
): LoggerLevel {
74+
if (method in LOGGER_LEVELS) {
75+
return method as LoggerLevel;
76+
}
77+
// categorize anything different from the common console methods as
78+
// a standard log (in the future if need be we can add logic here to
79+
// associate different methods to different log levels)
80+
return "log";
81+
}
82+
7183
export class Logger {
7284
constructor() {}
7385

@@ -127,7 +139,11 @@ export class Logger {
127139
if (typeof console[method] !== "function") {
128140
throw new Error(`console.${method}() is not a function`);
129141
}
130-
if (LOGGER_LEVELS[this.loggerLevel] !== LOGGER_LEVELS.none) {
142+
143+
if (
144+
LOGGER_LEVELS[this.loggerLevel] >=
145+
LOGGER_LEVELS[consoleMethodToLoggerLevel(method)]
146+
) {
131147
Logger.#beforeLogHook?.();
132148
(console[method] as (...args: unknown[]) => unknown).apply(console, args);
133149
Logger.#afterLogHook?.();

0 commit comments

Comments
 (0)