{"record":{"id":"24ced20ebd2d63d1","repo":"plandex-ai/plandex","slug":"failed-to-load-file-for-s-v","errorCode":null,"errorMessage":"failed to load file for %s: %v","messagePattern":"failed to load file for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/model_credentials.go","lineNumber":290,"sourceCode":"\t\tval := os.Getenv(cfg.ApiKeyEnvVar)\n\t\tif val != \"\" {\n\t\t\tauthVars[cfg.ApiKeyEnvVar] = val\n\t\t}\n\t}\n\n\tfor _, extra := range cfg.ExtraAuthVars {\n\t\tval := os.Getenv(extra.Var)\n\t\tif val == \"\" && extra.Default != \"\" {\n\t\t\tval = extra.Default\n\t\t}\n\n\t\tif extra.MaybeJSONFilePath {\n\t\t\tif val == \"\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tcontent, err := maybeLoadFile(val)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to load file for %s: %v\", extra.Var, err)\n\t\t\t}\n\t\t\tauthVars[extra.Var] = content\n\t\t} else if val != \"\" {\n\t\t\tauthVars[extra.Var] = val\n\t\t}\n\t}\n\n\treturn authVars, nil\n}\n\nfunc maybeLoadFile(pathOrJson string) (string, error) {\n\tif strings.HasPrefix(strings.TrimSpace(pathOrJson), \"{\") {\n\t\t// var contains json directly, so we can return it as is\n\t\treturn pathOrJson, nil\n\t}\n\n\t// see if it's base64 encoded json\n\tdecoded, err := base64.StdEncoding.DecodeString(pathOrJson)","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/model_credentials.go#L272-L308","documentation":"ResolveProviderAuthVars treats certain ExtraAuthVars (MaybeJSONFilePath) as either inline JSON, base64-encoded JSON, or a path to a JSON file. When the value is not JSON and os.ReadFile fails, the library wraps the read error as 'failed to load file for <VAR>'. The credential var could not be populated.","triggerScenarios":"Setting an ExtraAuthVar (e.g. a service-account key var) to a path that does not exist, is unreadable, or contains neither JSON nor base64-encoded JSON nor a valid file path.","commonSituations":"GOOGLE_APPLICATION_CREDENTIALS-style var pointing at a deleted key file after cleanup, base64 value that decodes but is not JSON, mounting the secret at a different path in CI than locally, or relative paths resolved against an unexpected working directory.","solutions":["Verify the file at the env-var path exists and is readable (ls / cat it as the running user).","Use an absolute path; relative paths resolve against the process working directory.","If embedding credentials, ensure the value is raw JSON starting with '{' or valid base64 whose decoded content starts with '{'.","Re-download/regenerate the credential file (e.g. a new service-account key) if it was deleted or rotated."],"exampleFix":"// before\nexport GOOGLE_APPLICATION_CREDENTIALS=\"./key.json\"\n// after\nexport GOOGLE_APPLICATION_CREDENTIALS=\"/etc/secrets/service-account-key.json\" # absolute, existing file\n\ntest -r \"$GOOGLE_APPLICATION_CREDENTIALS\" || echo \"credential file missing\"","handlingStrategy":"validation","validationCode":"func validateCredentialFilePath(envVar string) error {\n    v := os.Getenv(envVar)\n    if v == \"\" || strings.HasPrefix(strings.TrimSpace(v), \"{\") { return nil }\n    if _, err := base64.StdEncoding.DecodeString(v); err == nil { return nil }\n    if _, err := os.Stat(v); err != nil { return fmt.Errorf(\"%s points to unreadable file: %w\", envVar, err) }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"content, err := maybeLoadFile(val)\nif err != nil {\n    return nil, fmt.Errorf(\"check %s: must be JSON, base64 JSON, or a readable file path: %w\", envVarName, err)\n}","preventionTips":["Always use absolute, existing paths for credential files","Validate env vars at startup (stat the paths)","Remember the value must start with '{' to be treated as inline JSON","Regenerate key files after cleanup scripts or image rebuilds"],"tags":["credentials","filesystem","config"],"backgroundTag":"credentials-file-not-found","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}