{"record":{"id":"23c0bb8442129311","repo":"sigoden/aichat","slug":"no-application-default-credentials-json","errorCode":null,"errorMessage":"No application_default_credentials.json","messagePattern":"No application_default_credentials\\.json","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/client/vertexai.rs","lineNumber":496,"sourceCode":"        .await?;\n\n    if let (Some(access_token), Some(expires_in)) =\n        (value[\"access_token\"].as_str(), value[\"expires_in\"].as_i64())\n    {\n        Ok((access_token.to_string(), expires_in))\n    } else if let Some(err_msg) = value[\"error_description\"].as_str() {\n        bail!(\"{err_msg}\")\n    } else {\n        bail!(\"Invalid response data: {value}\")\n    }\n}\n\nasync fn load_adc(file: &Option<String>) -> Result<Value> {\n    let adc_file = file\n        .as_ref()\n        .map(PathBuf::from)\n        .or_else(default_adc_file)\n        .ok_or_else(|| anyhow!(\"No application_default_credentials.json\"))?;\n    let data = tokio::fs::read_to_string(adc_file).await?;\n    let data: Value = serde_json::from_str(&data)?;\n    if let (Some(client_id), Some(client_secret), Some(refresh_token)) = (\n        data[\"client_id\"].as_str(),\n        data[\"client_secret\"].as_str(),\n        data[\"refresh_token\"].as_str(),\n    ) {\n        Ok(json!({\n            \"client_id\": client_id,\n            \"client_secret\": client_secret,\n            \"refresh_token\": refresh_token,\n            \"grant_type\": \"refresh_token\",\n        }))\n    } else {\n        bail!(\"Invalid application_default_credentials.json\")\n    }\n}\n","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/client/vertexai.rs#L478-L514","documentation":"In src/client/vertexai.rs `load_adc`, no Application Default Credentials file could be located: the explicit `file` option was None and `default_adc_file()` (which probes `~/.config/gcloud/application_default_credentials.json` and platform equivalents) found nothing. The library throws this instead of attempting token refresh without credentials.","triggerScenarios":"Using the Vertex AI provider without an ADC file on disk and without a `file` path configured for ADC, so `.or_else(default_adc_file)` yields None.","commonSituations":"Fresh machine or CI container where `gcloud auth application-default login` was never run; running as a different user so $HOME points elsewhere; GCP_ADC_FILE-style config path typo.","solutions":["Run `gcloud auth application-default login` to create the default ADC file.","Point the client's ADC `file` config option at an existing credentials JSON.","Verify `default_adc_file`'s expected location exists (check $HOME/.config/gcloud/ on Linux/macOS, %APPDATA%/gcloud on Windows).","In CI, generate ADC via a service account key and set GOOGLE_APPLICATION_CREDENTIALS-style path in config."],"exampleFix":"// before (no credentials)\nError: No application_default_credentials.json\n\n// after\ngcloud auth application-default login","handlingStrategy":"validation","validationCode":"// Shell guard before invoking the tool\ntest -f \"$HOME/.config/gcloud/application_default_credentials.json\" \\\n  || { echo 'run: gcloud auth application-default login'; exit 1; }","typeGuard":null,"tryCatchPattern":"// Rust\nmatch run_vertexai().await {\n    Err(e) if e.to_string().contains(\"application_default_credentials.json\") => {\n    // prompt user to run gcloud auth application-default login\n    }\n    other => other?,\n}","preventionTips":["Run `gcloud auth application-default login` during machine/CI setup.","Bake ADC into container images for CI.","Point the ADC `file` config option explicitly when $HOME varies."],"tags":["gcp","credentials","oauth","file-not-found"],"backgroundTag":"missing-credentials","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}