Skip to content

Commit 53d76cd

Browse files
staticpayloadpetebacondarwin
authored andcommitted
wrangler: surface remote proxy session errors
1 parent 91b7f73 commit 53d76cd

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
@@ -6,6 +6,7 @@ import { getBasePath } from "../../paths";
66
import { startWorker } from "../startDevWorker";
77
import type { LoggerLevel } from "../../logger";
88
import type { StartDevWorkerInput, Worker } from "../startDevWorker";
9+
import type { ErrorEvent } from "../startDevWorker/events";
910
import type { Config } from "@cloudflare/workers-utils";
1011
import type { RemoteProxyConnectionString } from "miniflare";
1112

@@ -16,6 +17,46 @@ export type StartRemoteProxySessionOptions = {
1617
complianceRegion?: Config["compliance_region"];
1718
};
1819

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

76117
if (maybeError && maybeError.error) {
118+
const details = formatRemoteProxySessionError(maybeError.error);
77119
throw new Error(
78-
"Failed to start the remote proxy session. There is likely additional logging output above.",
120+
details
121+
? `Failed to start the remote proxy session. ${details}`
122+
: "Failed to start the remote proxy session. There is likely additional logging output above.",
79123
{
80124
cause: maybeError.error,
81125
}

0 commit comments

Comments
 (0)