Skip to content

Commit 0827815

Browse files
MattieTKedmundhung
andauthored
[wrangler] Add safe telemetry labels for user errors (#13722)
Co-authored-by: Edmund Hung <edmund@cloudflare.com>
1 parent 4d4d2c2 commit 0827815

212 files changed

Lines changed: 2105 additions & 836 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/fix-buffer-devalue.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
fix: normalise typed array subclasses in devalue serialization
66

7-
Node.js `Buffer` extends `Uint8Array` but isn't available in all runtimes. When
8-
a `Buffer` was passed through the proxy serialization bridge (e.g. as a D1 bind
9-
parameter via `getPlatformProxy()`), the reviver would fail because `"Buffer"`
10-
isn't in the allowed constructor list and may not exist on `globalThis` in workerd.
7+
Node.js `Buffer` extends `Uint8Array` but isn't available in all runtimes. When a `Buffer` was passed through the proxy serialization bridge (e.g. as a D1 bind parameter via `getPlatformProxy()`), the reviver would fail because `"Buffer"` isn't in the allowed constructor list and may not exist on `globalThis` in workerd.
118

12-
The reducer now normalises subclass constructor names to the nearest standard
13-
typed array parent before serialization, matching structured clone behaviour.
9+
The reducer now normalises subclass constructor names to the nearest standard typed array parent before serialization, matching structured clone behaviour.

.changeset/quiet-timers-teach.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+
Improve safe telemetry categorisation for user-facing Wrangler errors.

packages/cli/check-macos-version.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export function checkMacOSVersion(options: { shouldThrow: boolean }): void {
3232
throw new UserError(
3333
`Unsupported macOS version: The Cloudflare Workers runtime cannot run on the current version of macOS (${macOSVersion}). ` +
3434
`The minimum requirement is macOS ${MINIMUM_MACOS_VERSION}+. See https://github.com/cloudflare/workerd?tab=readme-ov-file#running-workerd ` +
35-
`If you cannot upgrade your version of macOS, you could try running in a DevContainer setup with a supported version of Linux (glibc 2.35+ required).`
35+
`If you cannot upgrade your version of macOS, you could try running in a DevContainer setup with a supported version of Linux (glibc 2.35+ required).`,
36+
{ telemetryMessage: false }
3637
);
3738
} else {
3839
/* eslint-disable-next-line no-console -- this package has no logger to use

packages/containers-shared/src/build.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ export function dockerBuild(
7777
resolve();
7878
} else if (!errorHandled) {
7979
errorHandled = true;
80-
reject(new UserError(`Docker build exited with code: ${code}`));
80+
reject(
81+
new UserError(`Docker build exited with code: ${code}`, {
82+
telemetryMessage: false,
83+
})
84+
);
8185
}
8286
});
8387
child.on("error", (err) => {

packages/containers-shared/src/images.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ export async function prepareContainerImagesForDev(args: {
112112
let aborted = false;
113113
if (process.platform === "win32") {
114114
throw new UserError(
115-
"Local development with containers is currently not supported on Windows. You should use WSL instead. You can also set `enable_containers` to false if you do not need to develop the container part of your application."
115+
"Local development with containers is currently not supported on Windows. You should use WSL instead. You can also set `enable_containers` to false if you do not need to develop the container part of your application.",
116+
{ telemetryMessage: false }
116117
);
117118
}
118119
await verifyDockerInstalled(dockerPath);
@@ -266,7 +267,8 @@ export const getAndValidateRegistryType = (domain: string): RegistryPattern => {
266267
.map((r) => r.name)
267268
.join(", ");
268269
throw new UserError(
269-
`${url.hostname} is not a supported image registry.\nCurrently we support the following non-Cloudflare registries: ${supportedRegistries}.\nTo use an existing image from another repository, see https://developers.cloudflare.com/containers/platform-details/image-management/#using-pre-built-container-images`
270+
`${url.hostname} is not a supported image registry.\nCurrently we support the following non-Cloudflare registries: ${supportedRegistries}.\nTo use an existing image from another repository, see https://developers.cloudflare.com/containers/platform-details/image-management/#using-pre-built-container-images`,
271+
{ telemetryMessage: false }
270272
);
271273
}
272274

packages/containers-shared/src/inspect.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export async function dockerImageInspect(
2323
proc.on("close", (code) => {
2424
if (code !== 0) {
2525
return reject(
26-
new UserError(`failed inspecting image locally: ${stderr.trim()}`)
26+
new UserError(`failed inspecting image locally: ${stderr.trim()}`, {
27+
telemetryMessage: false,
28+
})
2729
);
2830
}
2931
resolve(stdout.trim());

packages/containers-shared/src/login.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export async function dockerLoginImageRegistry(
5454
if (code === 0) {
5555
resolve();
5656
} else {
57-
reject(new UserError(`Login failed with code: ${code}`));
57+
reject(
58+
new UserError(`Login failed with code: ${code}`, {
59+
telemetryMessage: false,
60+
})
61+
);
5862
}
5963
});
6064
});

packages/containers-shared/src/utils.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ export const runDockerCmd = (
4242
resolve({ aborted });
4343
} else if (!errorHandled) {
4444
errorHandled = true;
45-
reject(new UserError(`Docker command exited with code: ${code}`));
45+
reject(
46+
new UserError(`Docker command exited with code: ${code}`, {
47+
telemetryMessage: false,
48+
})
49+
);
4650
}
4751
});
4852
child.on("error", (err) => {
4953
if (!errorHandled) {
5054
errorHandled = true;
51-
reject(new UserError(`Docker command failed: ${err.message}`));
55+
reject(
56+
new UserError(`Docker command failed: ${err.message}`, {
57+
telemetryMessage: false,
58+
})
59+
);
5260
}
5361
});
5462
return {
@@ -78,7 +86,8 @@ export const runDockerCmdWithOutput = (dockerPath: string, args: string[]) => {
7886
return stdout.trim();
7987
} catch (error) {
8088
throw new UserError(
81-
`Failed running docker command: ${(error as Error).message}. Command: ${dockerPath} ${args.join(" ")}`
89+
`Failed running docker command: ${(error as Error).message}. Command: ${dockerPath} ${args.join(" ")}`,
90+
{ telemetryMessage: false }
8291
);
8392
}
8493
};
@@ -104,7 +113,8 @@ export const verifyDockerInstalled = async (
104113
throw new UserError(
105114
`The Docker CLI could not be launched. Please ensure that the Docker CLI is installed and the daemon is running.\n` +
106115
`Other container tooling that is compatible with the Docker CLI and engine may work, but is not yet guaranteed to do so. You can specify an executable with the environment variable WRANGLER_DOCKER_BIN and a socket with DOCKER_HOST.` +
107-
`${isDev ? "\nTo suppress this error if you do not intend on triggering any container instances, set dev.enable_containers to false in your Wrangler config or passing in --enable-containers=false." : ""}`
116+
`${isDev ? "\nTo suppress this error if you do not intend on triggering any container instances, set dev.enable_containers to false in your Wrangler config or passing in --enable-containers=false." : ""}`,
117+
{ telemetryMessage: false }
108118
);
109119
}
110120
};
@@ -190,7 +200,8 @@ export async function checkExposedPorts(
190200
if (output === "0") {
191201
throw new UserError(
192202
`The container "${options.class_name}" does not expose any ports. In your Dockerfile, please expose any ports you intend to connect to.\n` +
193-
"For additional information please see: https://developers.cloudflare.com/containers/local-dev/#exposing-ports.\n"
203+
"For additional information please see: https://developers.cloudflare.com/containers/local-dev/#exposing-ports.\n",
204+
{ telemetryMessage: false }
194205
);
195206
}
196207
}

packages/containers-shared/tests/docker-context.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ describe.skipIf(process.platform !== "linux" && process.env.CI === "true")(
4848
expect,
4949
}) => {
5050
vi.mocked(execFileSync).mockImplementation(() => {
51-
throw new UserError("Docker command failed");
51+
throw new UserError("Docker command failed", {
52+
telemetryMessage: false,
53+
});
5254
});
5355

5456
const result = resolveDockerHost("/no/op/docker");

packages/vite-plugin-cloudflare/src/plugins/dev.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ export const devPlugin = createPlugin("dev", (ctx) => {
250250
"To use images from the Cloudflare-managed registry with the Vite plugin, " +
251251
"set the CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID environment variables.\n" +
252252
"The API token requires Containers:Edit and Workers Scripts:Edit permissions.\n" +
253-
"Alternatively, use a Dockerfile that references the image via FROM."
253+
"Alternatively, use a Dockerfile that references the image via FROM.",
254+
{ telemetryMessage: false }
254255
);
255256
}
256257

0 commit comments

Comments
 (0)