charmbracelet/crush · error

failed to configure providers during reload: %w

Error message

failed to configure providers during reload: %w

What it means

After providers load, cfg.configureProviders wires OAuth token handling, env, and per-provider clients into the reloaded config. If that setup fails, reload aborts with this wrapped error and the store rolls back to its previous state. Unlike provider loading, this is always fatal — there is no partial-success path.

Source

Thrown at internal/config/store.go:1252

	// Reconfigure providers
	env := env.New()
	resolver := NewShellVariableResolver(env)

	// Apply top-level env vars before configuring providers so variables
	// like AWS_PROFILE are visible to the AWS SDK credential chain.
	cfg.applyEnv(resolver)

	providers, err := Providers(cfg)
	if err != nil {
		if len(providers) == 0 {
			return fmt.Errorf("failed to load providers during reload: %w", err)
		}
		slog.Warn("Reload continuing with the previously known providers", "error", err)
	}

	if err := cfg.configureProviders(ctx, s, env, resolver, providers); err != nil {
		return fmt.Errorf("failed to configure providers during reload: %w", err)
	}

	// Update store state BEFORE running model/agent setup (so they see new config)
	s.setConfig(cfg)
	s.loadedPaths = loadedPaths
	s.resolver = resolver
	s.knownProviders = providers
	s.overrides = overrides
	s.workspacePath = workspacePath

	// Mirror startup flow: setup models and agents against NEW config.
	var setupErr error
	if !cfg.IsConfigured() {
		slog.Warn("No providers configured after reload")
	} else {
		resolved, resolveErr := resolveSelectedModels(cfg, providers)
		if resolveErr != nil {
			setupErr = fmt.Errorf("failed to configure selected models during reload: %w", resolveErr)

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Read the wrapped cause: fix the specific provider setup failure (re-auth OAuth, install the credential helper, restore file permissions).
  2. Remove the problematic provider's oauth/api_key entry and re-add it cleanly, then reload.
  3. Retry reload after fixing the data directory permissions or disk condition.
  4. If triggered by a transient credential helper failure, restart the helper/CLI and reload again.

Example fix

// before: corrupt oauth block breaks configureProviders
providers.copilot.oauth = {access_token: "", refresh_token: "garbage"}
// after: clear it and re-auth
providers.copilot.oauth = null  // then run the login flow
Defensive patterns

Strategy: try-catch

Validate before calling

if hasCorruptOAuth(cfg) || !isDataDirWritable(dataDir) { repairBeforeReload() }

Try / catch

if err := reload(); err != nil {
    var perr *ProviderConfigError
    if errors.As(err, &perr) { resetProviderAuth(perr.ProviderID); reload() }
}

Prevention

When it happens

Trigger: cfg.configureProviders(ctx, s, env, resolver, providers) returns an error: OAuth token application/persistence fails for a provider, an auth callback setup fails, or provider-specific configuration (e.g. base URL resolution, credential discovery like Copilot/LSP token lookup) errors out.

Common situations: A stored OAuth token is corrupt so applyToken fails; credential helper (e.g. Copilot CLI) not installed; data directory became read-only between load and configure.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/fb3234adbc3a6ba9. Report an issue: GitHub.