Skip to content

feat: name misconfigured environment variables on startup - #1176

Closed
bsaurusrex wants to merge 1 commit into
tinyauthapp:mainfrom
bsaurusrex:feat/config-diagnostics
Closed

bsaurusrex wants to merge 1 commit into
tinyauthapp:mainfrom
bsaurusrex:feat/config-diagnostics

Conversation

@bsaurusrex

@bsaurusrex bsaurusrex commented Oct 9, 2026 •

Copy link
Copy Markdown

Refs #685 (one of four small, independent PRs from that thread; they merge cleanly in any order)

Problem

Most startup reports in #685 were renamed or misspelled environment variables after the v5 config change, and the errors did not name them:

  • an unset app URL failed with failed to parse app url: invalid url;
  • TINYAUTH_* variables that match no config section were dropped silently, e.g. TINYAUTH_SECURECOOKIE instead of TINYAUTH_AUTH_SECURECOOKIE, so a setting looks enabled but isn't;
  • a bad value inside a known section reported only the internal node name (node: databasepath).

Change

  • Unset app URL: the error says it is not set and how to set it (TINYAUTH_APPURL, --appurl or appUrl in the config file). It notes that environment variables are ignored once a config file or CLI flags are used, and points at APP_URL / TINYAUTH_APP_URL if one of those v4-style names is set.
  • Unknown TINYAUTH_* variables are logged as one warning through the app logger after startup. Kubernetes service-link variables (TINYAUTH_SERVICE_HOST, TINYAUTH_PORT_...) are skipped.
  • On a decode failure, the error lists the variables that fail on their own (check TINYAUTH_X, TINYAUTH_Y).
  • Fixes the https(s) typo in the app URL format error.

No config is changed or mutated; this is diagnostics only.

Testing

  • make vet, make test and go test -race ./... pass.
  • New loader_env_test.go covers unknown and invalid detection and the Kubernetes exclusions.
  • Run in a container with the variables from the [BUG] Startup issues with v5 - report here #685 reports: APP_URL, TINYAUTH_APP_URL, misspelled roots, and an invalid value inside a known section. Each one now names the variable.

AI disclosure (per AI_POLICY.md): the code, tests and this description were written with Claude Code (Claude Opus 5.5), and the commit carries a Co-Authored-By trailer. I reviewed the change myself and tested it as described below.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Configuration errors now identify environment variables with invalid values without exposing those values.
    • Startup warnings flag unrecognized configuration environment variables, excluding Kubernetes service-link variables.
    • Empty or incorrectly formatted app URLs now produce clearer error messages, including guidance when legacy URL variables are set.

@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: tinyauthapp/tinyauth/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dc359257-344a-4ff9-9b70-fa64120b85bd
📥 Commits

Reviewing files that changed from the base of the PR and between 8455e04 and 9ac8416.

📒 Files selected for processing (2)
  • internal/utils/loaders/loader_env.go
  • internal/utils/loaders/loader_env_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

Environment loading now identifies unknown and invalid variables and avoids exposing decoder values in errors. The command passes unknown names to bootstrap setup for warnings. Empty App URLs and invalid URL formats receive updated error messages.

Changes

Environment configuration diagnostics

Layer / File(s) Summary
Identify environment variable issues
internal/utils/loaders/loader_env.go, internal/utils/loaders/loader_env_test.go
EnvLoader records unknown prefixed variables and reports rejected variable names when decoding fails. Errors do not expose decoder values. Tests cover filtering, duplicate names, and configuration immutability.
Pass findings into bootstrap setup
cmd/tinyauth/tinyauth.go, internal/bootstrap/app_bootstrap.go, internal/utils/app_utils.go
The command passes unknown variable names to BootstrapApp, which logs a warning when names are present. Setup returns targeted errors for empty App URLs and identifies legacy URL variable names. URL parsing error text is updated.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant RootCommand
  participant EnvLoader
  participant runCmd
  participant BootstrapApp
  RootCommand->>EnvLoader: Load environment configuration
  EnvLoader-->>RootCommand: Return ignored variable names
  RootCommand->>runCmd: Pass ignored variable names
  runCmd->>BootstrapApp: Set ignored variables
  BootstrapApp->>BootstrapApp: Log warning and validate App URL
Loading

Merge Risk: ⚪ Minimal · up to 9ac84

The startup diagnostics are mergeable after normal checks; no material issue remains identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: startup diagnostics that identify misconfigured environment variables.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Most startup failures reported after the v5 configuration change were
renamed or misspelled environment variables, and the errors did not
name them:

- an unset app url failed with "failed to parse app url: invalid url".
  It now says the app url is not set and how to set it, and points at
  APP_URL / TINYAUTH_APP_URL when one of those (v4 style) is set.
- TINYAUTH_ variables that match no configuration section were silently
  ignored. They are now logged as a warning once the logger is set up.
  Kubernetes service link variables (TINYAUTH_SERVICE_HOST, TINYAUTH_PORT,
  ...) are skipped.
- a variable inside a known section that fails to decode only reported
  the internal node name (e.g. "node: databasepath"). The error now
  lists the variables that fail to decode on their own, and no longer
  propagates the decoder error, which could echo the offending value
  (a secret pasted into the wrong variable) into the logs.

Also fixes the "https(s)" typo in the app url format error.

Refs tinyauthapp#685

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bsaurusrex
bsaurusrex force-pushed the feat/config-diagnostics branch from 8455e04 to 9ac8416 Compare October 9, 2026 06:25
@steveiliop56

Copy link
Copy Markdown
Member

@bsaurusrex Thanks for the contribution! I'm not sure this additional check is necessary, since configuration parsing already fails by design when an invalid recognized environment variable is provided. I think the existing behavior is sufficient without introducing additional warnings or validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants