crewAIInc/crewAI · error · ValueError

Failed to update OAuth2 settings: {e!s}

Error message

Failed to update OAuth2 settings: {e!s}

What it means

Raised by the enterprise connect flow while persisting the fetched OAuth2 settings into local CLI settings. After discovery succeeds, _update_oauth_settings writes enterprise_base_url, provider, audience, client_id, domain and extra via settings_command.set(); any exception there (missing settings key, unwritable config file, serialization failure of the extra dict) is wrapped as ValueError('Failed to update OAuth2 settings: ...').

Source

Thrown at lib/cli/src/crewai_cli/enterprise/main.py:90

    ) -> None:
        try:
            config_mapping = {
                "enterprise_base_url": enterprise_url,
                "oauth2_provider": oauth_config["provider"],
                "oauth2_audience": oauth_config["audience"],
                "oauth2_client_id": oauth_config["device_authorization_client_id"],
                "oauth2_domain": oauth_config["domain"],
                "oauth2_extra": oauth_config["extra"],
            }

            console.print("🔄 Updating local OAuth2 configuration...")

            for key, value in config_mapping.items():
                self.settings_command.set(key, value)
                console.print(f"  ✓ Set {key}: {value}", style="dim")

        except Exception as e:
            raise ValueError(f"Failed to update OAuth2 settings: {e!s}") from e

    def _validate_oauth_config(self, oauth_config: dict[str, Any]) -> None:
        required_fields = [
            "audience",
            "domain",
            "device_authorization_client_id",
            "provider",
            "extra",
        ]

        missing_basic_fields = [
            field for field in required_fields if field not in oauth_config
        ]
        missing_provider_specific_fields = [
            field
            for field in self._get_provider_specific_fields(oauth_config["provider"])
            if field not in oauth_config.get("extra", {})
        ]

View on GitHub (pinned to 754d7323be)

Solutions

  1. Check str(e) in the message: it names the failing setting operation
  2. Ensure the crewai settings file exists and is writable (check permissions on the config path shown by `crewai settings list`)
  3. Restore or delete the corrupted settings file so it is recreated, then re-run enterprise connect
  4. Upgrade the CLI to match the enterprise server version if a settings-key mismatch is indicated
Defensive patterns

Strategy: validation

Validate before calling

import os
from crewai_cli.config import Settings

def settings_writable() -> bool:
    s = Settings()
    path = getattr(s, "file_path", None) or os.path.join(os.path.expanduser("~"), ".crewai", "settings.toml")
    return os.access(os.path.dirname(path) or ".", os.W_OK)

Try / catch

try:
    enterprise_cmd.connect(url)
except ValueError as e:
    if "Failed to update OAuth2 settings" in str(e):
        # settings store unwritable/corrupt — fix perms or recreate file, then retry
        ...

Prevention

When it happens

Trigger: `crewai enterprise connect <url>` where discovery succeeds but a settings_command.set(key, value) call throws — e.g. the local settings store is read-only, the settings file is corrupted, or an unknown/renamed setting key is passed after a CLI downgrade.

Common situations: Read-only $HOME or container filesystems, a corrupted crewai settings file (invalid TOML/JSON), running an old CLI against a newer enterprise config that expects new setting keys, or permission problems on the config directory.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/be2991b6dd61f1ae. Report an issue: GitHub.