Skip to content

Commit 3cc3f6b

Browse files
chai1anypenalosa
authored andcommitted
[wrangler] Surface remote proxy session errors (#11896)
1 parent 36941d8 commit 3cc3f6b

6 files changed

Lines changed: 62 additions & 10 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Surface remote proxy session errors
6+
7+
When remote bindings fail to start, include the controller reason and root
8+
cause in the error message to make failures like missing `cloudflared` clearer.

fixtures/get-platform-proxy-remote-bindings/tests/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ if (auth) {
246246
}>({
247247
configPath: "./.tmp/config-with-invalid-account-id/wrangler.json",
248248
})
249-
).rejects.toMatchInlineSnapshot(
250-
`[Error: Failed to start the remote proxy session. There is likely additional logging output above.]`
249+
).rejects.toThrowError(
250+
/Failed to start the remote proxy session\. Failed to create a preview token/
251251
);
252252

253253
expect(errorSpy).toHaveBeenCalledOnce();

packages/vite-plugin-cloudflare/e2e/remote-bindings.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ if (isWindows) {
185185
expect(proc.stderr).toContain(
186186
"R2 bucket 'non-existent-r2-bucket' not found. Verify the bucket exists in your account and that the bucket_name in your configuration is correct. [code: 10085]"
187187
);
188-
expect(proc.stderr).toContain(
189-
"Error: Failed to start the remote proxy session. There is likely additional logging output above."
188+
expect(proc.stderr).toMatch(
189+
/Error: Failed to start the remote proxy session\./
190190
);
191191
});
192192
});

packages/wrangler/e2e/remote-binding/remote-bindings-api.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
9999
},
100100
}
101101
)
102-
).rejects.toMatchInlineSnapshot(
103-
`[Error: Failed to start the remote proxy session. There is likely additional logging output above.]`
102+
).rejects.toThrowError(
103+
/Failed to start the remote proxy session\. Failed to create a preview token/
104104
);
105105
});
106106
});
@@ -156,8 +156,8 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
156156
},
157157
}
158158
)
159-
).rejects.toMatchInlineSnapshot(
160-
`[Error: Failed to start the remote proxy session. There is likely additional logging output above.]`
159+
).rejects.toThrowError(
160+
/Failed to start the remote proxy session\. Failed to create a preview token/
161161
);
162162
});
163163
});

packages/wrangler/src/__tests__/dev/remote-bindings-errors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe("errors during dev with remote bindings", () => {
8888
assert(thrownError);
8989

9090
expect(thrownError).toMatchInlineSnapshot(
91-
`[Error: Failed to start the remote proxy session. There is likely additional logging output above.]`
91+
`[Error: Failed to start the remote proxy session. Failed to obtain a preview token: The remote worker preview failed.]`
9292
);
9393

9494
expect(thrownError.cause).toMatchInlineSnapshot(`

packages/wrangler/src/api/remoteBindings/start-remote-proxy-session.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getBasePath } from "../../paths";
88
import { startWorker } from "../startDevWorker";
99
import type { LoggerLevel } from "../../logger";
1010
import type { StartDevWorkerInput, Worker } from "../startDevWorker";
11+
import type { ErrorEvent } from "../startDevWorker/events";
1112
import type { Config } from "@cloudflare/workers-utils";
1213
import type { RemoteProxyConnectionString } from "miniflare";
1314

@@ -18,6 +19,46 @@ export type StartRemoteProxySessionOptions = {
1819
complianceRegion?: Config["compliance_region"];
1920
};
2021

22+
function isErrorEvent(error: unknown): error is ErrorEvent {
23+
return (
24+
typeof error === "object" &&
25+
error !== null &&
26+
"type" in error &&
27+
(error as { type?: string }).type === "error" &&
28+
"reason" in error &&
29+
"cause" in error
30+
);
31+
}
32+
33+
function getErrorMessage(error: unknown): string | undefined {
34+
if (error instanceof Error) {
35+
return getErrorMessage(error.cause) ?? error.message;
36+
}
37+
38+
if (typeof error === "string") {
39+
return error;
40+
}
41+
42+
if (typeof error === "object" && error !== null) {
43+
const maybeMessage = (error as { message?: unknown }).message;
44+
if (typeof maybeMessage === "string") {
45+
const maybeCause = (error as { cause?: unknown }).cause;
46+
return getErrorMessage(maybeCause) ?? maybeMessage;
47+
}
48+
}
49+
50+
return undefined;
51+
}
52+
53+
function formatRemoteProxySessionError(error: unknown): string | undefined {
54+
if (isErrorEvent(error)) {
55+
const causeMessage = getErrorMessage(error.cause);
56+
return causeMessage ? `${error.reason}: ${causeMessage}` : error.reason;
57+
}
58+
59+
return getErrorMessage(error);
60+
}
61+
2162
export async function startRemoteProxySession(
2263
bindings: StartDevWorkerInput["bindings"],
2364
options?: StartRemoteProxySessionOptions
@@ -77,8 +118,11 @@ export async function startRemoteProxySession(
77118
]);
78119

79120
if (maybeError && maybeError.error) {
121+
const details = formatRemoteProxySessionError(maybeError.error);
80122
throw new Error(
81-
"Failed to start the remote proxy session. There is likely additional logging output above.",
123+
details
124+
? `Failed to start the remote proxy session. ${details}`
125+
: "Failed to start the remote proxy session. There is likely additional logging output above.",
82126
{
83127
cause: maybeError.error,
84128
}

0 commit comments

Comments
 (0)