Gotchas
Common Errors
".get() Throws on Error"
Cause: Assuming .get() returns null on failure instead of throwing
Solution: Always wrap .get() calls in try/catch blocks to handle errors gracefully
typescript
try {
const key = await env.API_KEY.get();
} catch (error) {
return new Response("Configuration error", { status: 500 });
}"Logging Secret Values"
Cause: Accidentally logging secret values in console or error messages
Solution: Only log metadata (e.g., "Retrieved API_KEY") never the actual secret value
"Module-Level Secret Access"
Cause: Attempting to access secrets during module initialization before env is available
Solution: Cache secrets in request scope only, not at module level
"Secret not found in store"
Cause: Secret name doesn't exist, case mismatch, missing workers scope, or incorrect store_id