{"record":{"id":"d37a9e7133bb6738","repo":"router-for-me/CLIProxyAPI","slug":"core-auth-manager-unavailable-d37a9e","errorCode":null,"errorMessage":"core auth manager unavailable","messagePattern":"core auth manager unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pluginhost/auth_callbacks.go","lineNumber":222,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfiles = append(files, fileEntry)\n\t}\n\tsort.Slice(files, func(i, j int) bool {\n\t\treturn strings.ToLower(files[i].Name) < strings.ToLower(files[j].Name)\n\t})\n\treturn files, nil\n}\n\nfunc (h *Host) authByIndex(authIndex string) (*coreauth.Auth, error) {\n\tauthIndex = strings.TrimSpace(authIndex)\n\tif authIndex == \"\" {\n\t\treturn nil, fmt.Errorf(\"auth_index is required\")\n\t}\n\tmanager := h.currentAuthManager()\n\tif manager == nil {\n\t\treturn nil, fmt.Errorf(\"core auth manager unavailable\")\n\t}\n\tfor _, auth := range manager.List() {\n\t\tif auth == nil {\n\t\t\tcontinue\n\t\t}\n\t\tauth.EnsureIndex()\n\t\tif auth.Index == authIndex {\n\t\t\treturn auth, nil\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"auth not found for auth_index %s\", authIndex)\n}\n\nfunc (h *Host) authPhysicalJSONByIndex(authIndex string) (*coreauth.Auth, []byte, error) {\n\tauth, errGet := h.authByIndex(authIndex)\n\tif errGet != nil {\n\t\treturn nil, nil, errGet\n\t}","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/pluginhost/auth_callbacks.go#L204-L240","documentation":"Thrown by Host.authByIndex when the plugin host cannot resolve the core auth manager (h.currentAuthManager() returns nil). The auth manager is the shared registry of loaded credential files; without it, no auth_index can be resolved. It signals the host (or the SDK service backing it) was constructed or shut down without wiring the auth manager into the plugin host.","triggerScenarios":"Calling a plugin host auth callback (e.g. hostAuthsList/Get-by-index style API) before the core service registered its auth manager, after the host was stopped/torn down, or when the Host was built standalone (e.g. tests or a plugin-only host) with no coreauth manager attached.","commonSituations":"Unit tests instantiating pluginhost.Host directly without injecting an auth manager; invoking plugin callbacks during shutdown while a plugin goroutine is still processing a request; embedding the SDK but skipping the builder step that connects the auth store.","solutions":["Ensure the Host is created through the normal service builder path so the auth manager is set before any plugin callback runs","If constructing Host manually (tests/tools), inject the core auth manager via the host's setter/option before calling auth callbacks","Stop or gate plugin goroutines before tearing down the service so callbacks do not race manager teardown","Retry once after startup completes if the callback fired during initialization"],"exampleFix":"// before\nhost := pluginhost.New(opts) // no auth manager wired\nauth, err := host.AuthByIndex(\"abc\") // core auth manager unavailable\n\n// after\nhost := pluginhost.New(opts)\nhost.SetAuthManager(coreService.AuthManager()) // wire manager first\nauth, err := host.AuthByIndex(\"abc\")","handlingStrategy":"validation","validationCode":"// before calling an auth-by-index callback:\nif host.CurrentAuthManager() == nil {\n    return fmt.Errorf(\"auth manager not ready; wire it before use\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the plugin host via the standard service builder so the auth manager is always attached","Gate plugin callbacks on a started/ready flag set after manager wiring","Stop plugin goroutines before tearing down the core service"],"tags":["go","pluginhost","auth","initialization","lifecycle"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}