From d5153266f9a682114144d5c8733b88f8243b6f75 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 21 Feb 2025 17:49:25 +0000 Subject: [PATCH] fix incorrect (sync) `getCloudflareContext` error message --- .changeset/warm-lizards-lick.md | 9 +++++++++ packages/cloudflare/src/api/cloudflare-context.ts | 10 +++++----- 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 .changeset/warm-lizards-lick.md diff --git a/.changeset/warm-lizards-lick.md b/.changeset/warm-lizards-lick.md new file mode 100644 index 00000000..18820575 --- /dev/null +++ b/.changeset/warm-lizards-lick.md @@ -0,0 +1,9 @@ +--- +"@opennextjs/cloudflare": patch +--- + +fix incorrect (sync) `getCloudflareContext` error message + +currently `getCloudflareContext` run in sync mode at the top level of a not static route +gives a misleading error message saying that the function needs to be run in a not static +route, the changes here correct this error message clarifying that the problem actually is diff --git a/packages/cloudflare/src/api/cloudflare-context.ts b/packages/cloudflare/src/api/cloudflare-context.ts index 200afbc7..fd413d42 100644 --- a/packages/cloudflare/src/api/cloudflare-context.ts +++ b/packages/cloudflare/src/api/cloudflare-context.ts @@ -118,11 +118,11 @@ function getCloudflareContextSync< // normal global state so we throw with a helpful error message. if (inSSG()) { throw new Error( - `\n\nERROR: \`getCloudflareContext\` has been called in a static route,` + - ` that is not allowed, this can be solved in different ways:\n\n` + - ` - call \`getCloudflareContext({async: true})\` to use the \`async\` mode\n` + - ` - avoid calling \`getCloudflareContext\` in the route\n` + - ` - make the route non static\n` + `\n\nERROR: \`getCloudflareContext\` has been called in sync mode in either a static route or at the top level of a non-static one,` + + ` both cases are not allowed but can be solved by either:\n` + + ` - make sure that the call is not at the top level and that the route is not static\n` + + ` - call \`getCloudflareContext({async: true})\` to use the \`async\` mode\n` + + ` - avoid calling \`getCloudflareContext\` in the route\n` ); }