{"record":{"id":"ecb222f81032248b","repo":"mastra-ai/mastra","slug":"data-errors-0-message","errorCode":null,"errorMessage":"data.errors[0].message","messagePattern":"data\\.errors\\[0\\]\\.message","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deployers/cloudflare/src/secrets-manager/index.ts","lineNumber":39,"sourceCode":"    const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;\n\n    try {\n      const response = await fetch(url, {\n        method: 'PUT',\n        headers: {\n          Authorization: `Bearer ${this.apiToken}`,\n          'Content-Type': 'application/json',\n        },\n        body: JSON.stringify({\n          name: secretName,\n          text: secretValue,\n        }),\n      });\n\n      const data = (await response.json()) as { success: boolean; result: any; errors: any[] };\n\n      if (!data.success) {\n        throw new Error(data.errors[0].message);\n      }\n\n      return data.result;\n    } catch (error) {\n      console.error('Failed to create secret:', error);\n      throw error;\n    }\n  }\n\n  async createProjectSecrets({\n    workerId,\n    customerId,\n    envVars,\n  }: {\n    workerId: string;\n    customerId: string;\n    envVars: Record<string, string>;\n  }) {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/deployers/cloudflare/src/secrets-manager/index.ts#L21-L57","documentation":"`createSecret` calls the Cloudflare API and checks the response's `success` flag. When Cloudflare returns `success: false`, the code throws an Error built from `data.errors[0].message`, surfacing Cloudflare's own API error (auth failure, wrong account, permissions, validation) to the caller.","triggerScenarios":"Any Cloudflare API response with `success: false` while creating a project secret — invalid/expired API token, wrong account ID, missing Workers Secrets permission, or invalid secret payload — with a non-empty `errors` array.","commonSituations":"CLOUDFLARE_API_TOKEN unset, expired after rotation, or scoped to the wrong account; token lacking Workers Scripts:Edit; mistyped account ID; secret name violating Cloudflare naming rules.","solutions":["Read the thrown message (the first Cloudflare error) and fix the underlying issue it names.","Verify the API token via /user/tokens/verify and grant it Workers secret-write permission for the target account.","Check the account ID / project binding passed to the secrets manager matches the Cloudflare account owning the worker.","Harden the throw against empty `errors` arrays to avoid a confusing secondary TypeError, then retry."],"exampleFix":"// before\nthrow new Error(data.errors[0].message);\n// after\nthrow new Error(`Cloudflare createSecret failed: ${data.errors?.[0]?.message ?? JSON.stringify(data.errors)}`);","handlingStrategy":"try-catch","validationCode":"// Verify Cloudflare credentials before calling createSecret\nasync function assertCloudflareTokenWorks(token: string): Promise<void> {\n  const res = await fetch('https://api.cloudflare.com/client/v4/user/tokens/verify', {\n    headers: { Authorization: `Bearer ${token}` },\n  });\n  const json: { success: boolean; errors?: { message: string }[] } = await res.json();\n  if (!json.success) throw new Error(`Invalid Cloudflare token: ${json.errors?.[0]?.message ?? res.status}`);\n}","typeGuard":"interface CloudflareResponse { success: boolean; result: unknown; errors: { message: string }[] }\nfunction isCloudflareError(data: unknown): data is CloudflareResponse & { success: false; errors: [{ message: string }, ...{ message: string }[]] } {\n  const d = data as CloudflareResponse;\n  return d.success === false && Array.isArray(d.errors) && d.errors.length > 0 && typeof d.errors[0]?.message === 'string';\n}","tryCatchPattern":"try {\n  await secretsManager.createSecret(projectName, name, value);\n} catch (err) {\n  if (err instanceof Error && /token|authentication|permission|not authorized/i.test(err.message)) {\n    console.error('Cloudflare auth/permission problem creating secret:', err.message);\n  } else if (err instanceof TypeError) {\n    console.error('Unexpected Cloudflare response shape (errors array empty?):', err);\n  } else throw err;\n}","preventionTips":["Verify the API token with /user/tokens/verify and grant Workers secret-write scope before deploying.","Confirm the account ID in config matches the account owning the worker/project.","Log the full Cloudflare error payload, not just errors[0].message, to distinguish auth vs validation failures.","Rotate tokens before expiry and keep CLOUDFLARE_API_TOKEN current in CI."],"tags":["cloudflare","api","secrets","auth"],"backgroundTag":"cloudflare-api-error","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}