Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/secrets-store/gotchas.md
1# Gotchas23## Common Errors45### ".get() Throws on Error"67**Cause:** Assuming `.get()` returns null on failure instead of throwing8**Solution:** Always wrap `.get()` calls in try/catch blocks to handle errors gracefully910```typescript11try {12const key = await env.API_KEY.get();13} catch (error) {14return new Response("Configuration error", { status: 500 });15}16```1718### "Logging Secret Values"1920**Cause:** Accidentally logging secret values in console or error messages21**Solution:** Only log metadata (e.g., "Retrieved API_KEY") never the actual secret value2223### "Module-Level Secret Access"2425**Cause:** Attempting to access secrets during module initialization before env is available26**Solution:** Cache secrets in request scope only, not at module level2728### "Secret not found in store"2930**Cause:** Secret name doesn't exist, case mismatch, missing workers scope, or incorrect store_id31**Solution:** Verify secret exists with `wrangler secrets-store secret list <store-id> --remote`, check name matches exactly (case-sensitive), ensure secret has `workers` scope, and verify correct store_id3233### "Scope Mismatch"3435**Cause:** Secret exists but missing `workers` scope (only has `ai-gateway` scope)36**Solution:** Update secret scopes: `wrangler secrets-store secret update <store-id> --name SECRET --scopes workers --remote` or add via Dashboard3738### "JSON Parsing Failure"3940**Cause:** Storing invalid JSON in secret, then failing to parse during runtime41**Solution:** Validate JSON before storing:4243```bash44# Validate before storing45echo '{"key":"value"}' | jq . && \46echo '{"key":"value"}' | wrangler secrets-store secret create <store-id> \47--name CONFIG --scopes workers --remote48```4950Runtime parsing with error handling:5152```typescript53try {54const configStr = await env.CONFIG.get();55const config = JSON.parse(configStr);56} catch (error) {57console.error("Invalid config JSON:", error);58return new Response("Invalid configuration", { status: 500 });59}60```6162### "Cannot access secret in local dev"6364**Cause:** Attempting to access production secrets in local development environment65**Solution:** Create local-only secrets (without `--remote` flag) for development: `wrangler secrets-store secret create <store-id> --name API_KEY --scopes workers`6667### "Property 'get' does not exist"6869**Cause:** Missing TypeScript type definition for secret binding70**Solution:** Define interface with get method: `interface Env { API_KEY: { get(): Promise<string> }; }`7172### "Binding already exists"7374**Cause:** Duplicate binding in dashboard or conflict between wrangler.jsonc and dashboard75**Solution:** Remove duplicate from dashboard Settings → Bindings, check for conflicts, or delete old Worker secret with `wrangler secret delete API_KEY`7677### "Account secret quota exceeded"7879**Cause:** Account has reached 100 secret limit (beta)80**Solution:** Check quota with `wrangler secrets-store quota --remote`, delete unused secrets, consolidate duplicates, or contact Cloudflare for increase8182## Limits8384| Limit | Value | Notes |85|-------|-------|-------|86| Max secrets per account | 100 | Beta limit |87| Max stores per account | 1 | Beta limit |88| Max secret size | 1024 bytes | Per secret |89| Local secrets | Don't count toward limit | Only production secrets count |90| Scopes available | `workers`, `ai-gateway` | Must have correct scope for access |91| Scope | Account-level | Can be reused across multiple Workers |92| Access method | `await env.BINDING.get()` | Async only, throws on error |93| Management | Centralized | Via secrets-store commands |94| Local dev | Separate local secrets | Use without `--remote` flag |95| Regional availability | Global except China Network | Unavailable in China Network |9697See: [configuration.md](./configuration.md), [api.md](./api.md), [patterns.md](./patterns.md)98