Skip to content

Commit 405d52c

Browse files
xdefragclaude
andcommitted
docs: add critical rule for environment variable defaults
Add guideline to always provide fallback defaults for CLI flags and environment variables to prevent production crashes. Lesson learned from rate limiter deployment where missing RATE_LIMIT env var caused application to crash with zero value. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 494fc82 commit 405d52c

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ The application follows a layered architecture:
107107
- **Numbered Fields**: Account metadata like websites use numbered keys (Website0, Website1) parsed and sorted by `parseNumberedDataKeys()`
108108
- **Tag Fields**: Account tags use `Tag*` prefix keys (TagBelgrade, TagProgrammer) parsed by `parseTagKeys()`. Value is account ID (ignored for display).
109109
- **AND Filtering Pattern**: For requiring all values match, use `GROUP BY + HAVING COUNT(DISTINCT column) = N` in subqueries.
110-
- **Configuration**: Port via `--port`/`PORT`, Horizon URL via `--horizon-url`/`HORIZON_URL`, log level via `--log-level`/`LOG_LEVEL` (debug, info, warn, error), database URL via `--database-url`/`DATABASE_URL` (required)
110+
- **Configuration**: Port via `--port`/`PORT`, Horizon URL via `--horizon-url`/`HORIZON_URL`, log level via `--log-level`/`LOG_LEVEL` (debug, info, warn, error), database URL via `--database-url`/`DATABASE_URL` (required), rate limit via `--rate-limit`/`RATE_LIMIT` (default: 100)
111+
- **Environment Variable Defaults**: CRITICAL - Always provide fallback defaults for env vars/CLI flags. IntFlag/StringFlag return zero values when not set. Check for zero/empty and use `config.Default*` constants. Example: `if rateLimit <= 0 { rateLimit = config.DefaultRateLimit }`. Production crashes without defaults.
111112
- **Logging**: Uses `log/slog` with JSON output and source location. Log levels: `info` for lifecycle events, `error` for unexpected failures (not expected errors like 404), `debug` for troubleshooting
112113
- **Token Constants**: Defined in `internal/config/config.go` (MTLAP, MTLAC, issuer address)
113114
- **Template Inheritance**: Each page template must be cloned from base separately (see `template.go`). Using `ParseFS` with multiple templates defining the same block causes overwrites.

0 commit comments

Comments
 (0)