#337·plandex

Replace panic() with error returns in model validation init

Author: 1CkpweeCreated Apr 8, 2026Updated Apr 8, 2026

Problem

In app/shared/ai_models_available.go, the init() function uses 12 panic() calls to validate model configurations at startup (around lines 667-711). If any model config is incomplete — e.g., missing a description or default max tokens — the entire application crashes immediately without any opportunity for graceful error handling or user-friendly messaging.

Example pattern:

go
if modelConfig.Description == "" {
    panic("...")
}

This is especially problematic because:

  1. Users who add custom models or modify configs get an opaque crash with no recovery path
  2. The panic trace is not user-friendly — it shows Go internals rather than actionable guidance
  3. It prevents partial startup (e.g., skipping a misconfigured model but proceeding with valid ones)

Similarly, app/server/db/fs.go:15 and app/server/db/git.go:28 panic during init if the home directory can't be found or git isn't installed, rather than returning errors.

Proposed solution

  • Replace panic() calls with a validation function that returns error
  • Call validation at server startup, log warnings for invalid models, and skip them gracefully
  • For critical dependencies (git, home dir), return a clear error message at startup rather than panicking

This would make Plandex more robust for self-hosted deployments where environment setup may vary.