{"record":{"id":"2d6cedff44681977","repo":"vxcontrol/pentagi","slug":"failed-to-create-provider-for-testing-w","errorCode":null,"errorMessage":"failed to create provider for testing: %w","messagePattern":"failed to create provider for testing: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/providers/providers.go","lineNumber":888,"sourceCode":"\tcase pconfig.OptionsTypeInstaller:\n\t\ttestConfig.Installer = config\n\tcase pconfig.OptionsTypePentester:\n\t\ttestConfig.Pentester = config\n\tdefault:\n\t\treturn result, fmt.Errorf(\"unsupported agent type: %s\", agentType)\n\t}\n\n\t// Patch with defaults\n\tpatchedConfig, err := pc.patchProviderConfig(prvtype, testConfig)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"failed to patch provider config: %w\", err)\n\t}\n\n\t// Create temporary provider for testing using existing provider logic\n\tproviderName := provider.ProviderName(\"test-provider\")\n\ttempProvider, err := pc.buildProviderFromConfig(prvtype, providerName, patchedConfig)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"failed to create provider for testing: %w\", err)\n\t}\n\n\t// Run tests for specific agent type only\n\tresults, err := tester.TestProvider(\n\t\tctx,\n\t\ttempProvider,\n\t\ttester.WithAgentTypes(agentType),\n\t\ttester.WithVerbose(false),\n\t\ttester.WithParallelWorkers(defaultTestParallelWorkersNumber),\n\t)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"failed to test agent: %w\", err)\n\t}\n\n\t// Extract results for the specific agent type\n\tswitch agentType {\n\tcase pconfig.OptionsTypeSimple:\n\t\tresult = results.Simple","sourceCodeStart":870,"sourceCodeEnd":906,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/providers/providers.go#L870-L906","documentation":"TestAgent builds a temporary provider instance from the patched config via pc.buildProviderFromConfig to run connectivity tests. If the provider cannot be constructed — bad credentials, unsupported provider type, failed client initialization — the error is wrapped as \"failed to create provider for testing: %w\".","triggerScenarios":"buildProviderFromConfig returns an error for the given prvtype/patchedConfig: unrecognized provider type in the factory switch, missing API key/base URL, or an error from the provider SDK's constructor (e.g. invalid OpenAI/Anthropic key format).","commonSituations":"Testing a provider with an empty or malformed API key; provider type registered in config but not handled in buildProviderFromConfig; wrong base URL scheme (e.g. missing https://) rejected by SDK constructor.","solutions":["Read the wrapped inner error — it names the actual construction failure","Verify the API key and server URL are set and well-formed for the provider type","Confirm prvtype is handled in buildProviderFromConfig's switch (providers.go)","Use TestAgent's flow after successfully creating the provider via CreateProvider to validate the config first"],"exampleFix":"// before\ncfg := &pconfig.AgentConfig{APIKey: \"\", Model: \"gpt-4o\"} // empty key\n// after\ncfg := &pconfig.AgentConfig{APIKey: os.Getenv(\"OPENAI_API_KEY\"), Model: \"gpt-4o\"}\nif cfg.APIKey == \"\" {\n    return errors.New(\"OPENAI_API_KEY is required to test this agent\")\n}","handlingStrategy":"validation","validationCode":"if cfg.APIKey == \"\" || cfg.Model == \"\" {\n    return errors.New(\"API key and model are required before testing an agent\")\n}","typeGuard":null,"tryCatchPattern":"result, err := ctrl.TestAgent(ctx, prvtype, agentType, cfg)\nif err != nil && strings.Contains(err.Error(), \"failed to create provider for testing\") {\n    return fmt.Errorf(\"could not construct provider %s — check credentials and base URL: %w\", prvtype, err)\n}","preventionTips":["Verify API key format and presence before invoking test endpoints","Ensure the provider type is handled in buildProviderFromConfig","Use CreateProvider (which validates) as a dry-run before testing","Validate base URL scheme (https://) for custom endpoints"],"tags":["provider","initialization","credentials"],"backgroundTag":"provider-initialization-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}