GeezerVison is showing github.com — cloudflare-export: GraphQL errors assumed to be an array of {message: string} — other shapes throw TypeErrors misclassified as fetch-failed, and a single-object errors is silently ignored · Issue #2608 · developing-today/code
cloudflare-export: GraphQL errors assumed to be an array of {message: string} — other shapes throw TypeErrors misclassified as fetch-failed, and a single-object errors is silently ignored #2608Descriptioncloudflare-export: GraphQL errors is assumed to be an array of {message: string} — other shapes throw TypeErrors misclassified as fetch-failed, and a single-object errors is silently ignored
Evidence (verified this run, main 819889b)
pm-stack/cloudflare-export/cloudflare-quota-export.mjs, in run():
- Line 407:
const gqlErrors = gql.body?.errors ?? [];
- Line 408-409:
if (gqlErrors.length) { const msg = gqlErrors.map((e) => e.message.split("\n")[0]).join(" ; "); ... } — this assumes errors is an array whose every entry is an object with a string message. Nothing validates that shape, in a file whose other parsers (parseGraphqlUsage, classifyR2, foldKv, firstSum) are deliberately fail-closed on shape drift.
- Line 451 (
main()): any non-ExportError escaping run() is re-wrapped as new ExportError("fetch-failed", 7, "unexpected: ...").
Probe (laptop ~/git/fleet/probe-2026-10-30-laneB-cfgqlerr/probe.mjs, Bun, the real run() imported from the laptop clone — md5 0fbd8dae4f5eba83adb88ec6092d1039, byte-identical to sandbox main — with fetch stubbed; billing probes 200, buckets well-formed):
- Control, valid payload with no
errors: status: ok, 11 metrics.
- Control,
errors: [{message: "auth: permission denied"}]: correctly throws ExportError token-scope exit 3.
errors: "upstream exploded" (a string): TypeError — gqlErrors.map is not a function escapes run(); main() reclassifies it as fetch-failed / exit 7 with detail unexpected: ..., instead of the file's own unparseable / exit 6 for an unrecognised shape, and the GraphQL error text is lost.
errors: [null]: TypeError — null is not an object (evaluating 'e.message'), same fetch-failed/7 misclassification.
errors: [{message: 12345}]: TypeError — e.message.split is not a function, same misclassification.
errors: {message: "auth: permission denied"} (single object, no array) with a valid data payload alongside (GraphQL permits partial data + errors): the error is silently ignored — gqlErrors.length is undefined, so the branch never runs — and run() publishes a status: ok document with 11 metrics despite an auth/permission error entry. Without data, the same shape falls through to the generic "no account node in data" unparseable, and the token-scope classification (exit 3) the array form gets never fires.
Why it matters
This exporter's whole contract is its failure taxonomy (header comment, lines 36-40): token-scope (exit 3) tells the operator the token needs scopes, unparseable (6) says an endpoint answered an unknown shape, fetch-failed (7) says the network/other failed. A shape-drifted errors field currently lands in the wrong bucket — an on-call reader chasing a "fetch failure" finds a healthy network and no error text — and the single-object form can either hide an auth error behind a green status: ok document or strip it of its scope classification. The aggregator/gatherer side trusts these statuses to decide whether a Cloudflare reading is real.
Acceptance criteria
- The GraphQL
errors value is normalised/validated before use: a non-array errors, or entries that are not objects with a string message, produce ExportError("unparseable", 6, ...) naming the shape — never a bare TypeError escaping run().
- A single-object
errors (or any truthy non-array form triage decides to accept) is not silently ignored: its message goes through the same auth/permission/scope classification as the array form, or it is rejected as unparseable — triage pins which; an auth/permission error must never coexist with a published status: ok document.
-
main()'s classification of a GraphQL shape problem is unparseable/6, not fetch-failed/7.
- Regression tests in
cloudflare-quota-export.test.mjs cover: errors as a string, [null], [{message: <number>}], and a single-object errors, alongside the existing array controls (valid payload still exports status: ok; [{message: "auth: ..."}] still yields token-scope/3).
- Well-formed responses are unaffected: the existing cloudflare-export test suite passes unchanged.
Dedup: #2574 covers the R2 bucket enumeration in the same run() (fails-open r2Buckets: [] + pagination) — a different field and failure mode; this issue is only the GraphQL errors handling at lines 407-416. #2460 is the meta-exporter's timestamp misclassification, a different file. Activityadded kind/bugSomething isn't working (prefixed form of the classic bug label) task/triageQueue packet kind: verify, reproduce, and route this item effort/xsTrivial: expected under 30 minutes of work on Oct 30, 2026dezren39 commented on Oct 30, 2026 🤖 Agent note · filed
- Agent: new-issue-creator job (new-issue-creator-code-b)
- Session / ID: cron job new-issue-creator-code-b, run 2026-10-30 01:50 CDT
- Found via: filed this run
- Task: Filed this issue after verifying the GraphQL
errors shape handling in cloudflare-quota-export.mjs against the real run() on the laptop (stubbed fetch, main 819889b).
- Expectation: effort/xs triage — pin the normalisation/treatment for non-array and malformed
errors shapes, then route a small_fix packet.
- Links: packet packet-2608-triage.json (hidden_files, goal keep-the-four-repos-healthy); probe ~/git/fleet/probe-2026-10-30-laneB-cfgqlerr/ (laptop)
dezren39 commented on Nov 1, 2026 🤖 Agent note · done
Triage findings — CONFIRMED
Fresh verification at current main 199d9f2e2 (laptop primary clone, clean main):
pm-stack/cloudflare-export/cloudflare-quota-export.mjs:407-413 — const gqlErrors = gql.body?.errors ?? []; if (gqlErrors.length) { const msg = gqlErrors.map((e) => e.message.split("\n")[0]).join(" ; "); … } with the auth|permission|scope → token-scope classification and unparseable/6 fallback inside the branch. No shape validation anywhere.
main()'s catch wraps any non-ExportError as fetch-failed/7 (unexpected: …), so the bare TypeErrors from drifted shapes land in the wrong taxonomy bucket with the real error text mangled.
- A single-object
errors has no .length → the branch is skipped entirely → a valid data payload publishes status: ok with the error invisible.
The file is byte-identical between the filing probe's main (819889bb) and current main (empty git diff), so the probe carries verbatim (~/git/fleet/probe-2026-10-30-laneB-cfgqlerr/probe.mjs, real run(), stubbed fetch): valid control → ok, 11 metrics; array auth error → token-scope/3; errors as string → TypeError gqlErrors.map is not a function; [null] → TypeError on e.message; [{message: 12345}] → TypeError e.message.split is not a function; single-object auth error + valid data → status ok (silently ignored).
Pinned normalisation (task 5394)
- A single-object
errors whose message is a string wraps to a one-element array and takes exactly the array form's classification (auth/permission/scope → token-scope/3; otherwise unparseable/6 with the message). Never ignored, never behind status: ok.
- Every other drift —
errors as a string/number, null/non-object entries, missing or non-string message — throws ExportError("unparseable", 6, …) naming the shape. No bare TypeError escapes run(); non-string messages are not coerced (drift surfaces, it is not guessed — same idiom as supabase-export: billedFromAddons silently zeroes unpriced selected addons (and accepts negative amounts) — a paid addon reports as measured $0 #2492).
- Controls unchanged: missing/empty
errors, and valid arrays, behave exactly as today.
- Tests (
cloudflare-quota-export.test.mjs): string, [null], [{message: number}], single-object auth (→ token-scope/3), plus valid and auth-array controls; existing suite green.
- Out of scope: cloudflare-export: R2 bucket enumeration fails open — a 500/malformed buckets response publishes r2Buckets: [] in a status:ok document, and pagination past 100 buckets is silently dropped #2574 R2 enumeration,
parseGraphqlUsage, billing-probe classification, main()'s generic wrapping.
dezren39 commented on Nov 1, 2026 dezren39 commented on Nov 1, 2026 dezren39 commented on Nov 9, 2026 agent-note:v1
task: 4465
lane: code-o
stage: triaged
state: ownership record required by #3069 Phase 3 audit: this issue was fixed under its own small_fix (queue task 5394, PR #3463, merged 48eb4d3, closed completed 2026-11-01) — NOT under #2576 Phase 3 and NOT under #3068 Phase 3 (#3069). The as-built normalisation stands at pm-stack/cloudflare-export/cloudflare-quota-export.mjs:519-533. Recorded in doc/2026-11-09_audit_3068-phase3-closing.md (PR #7984). No further action here.
next: none.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|