{"record":{"id":"041aa5e50ecd29d7","repo":"Tencent/WeKnora","slug":"unknown-credential-field-s-041aa5","errorCode":null,"errorMessage":"unknown credential field: %s","messagePattern":"unknown credential field: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/web_search_provider.go","lineNumber":103,"sourceCode":"\t\treturn nil, fmt.Errorf(\"web search provider not found\")\n\t}\n\n\tif apiKey != nil && *apiKey != \"\" && *apiKey != existing.Parameters.APIKey {\n\t\texisting.Parameters.APIKey = *apiKey\n\t\tif err := s.repo.Update(ctx, existing); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tlogger.Infof(ctx, \"WebSearch provider credentials updated: tenant=%d id=%s\", tenantID, id)\n\t}\n\treturn existing, nil\n}\n\n// ClearProviderCredential clears the api_key credential. Idempotent.\nfunc (s *webSearchProviderService) ClearProviderCredential(\n\tctx context.Context, tenantID uint64, id, field string,\n) error {\n\tif field != \"api_key\" {\n\t\treturn fmt.Errorf(\"unknown credential field: %s\", field)\n\t}\n\texisting, err := s.repo.GetByID(ctx, tenantID, id)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif existing == nil {\n\t\treturn fmt.Errorf(\"web search provider not found\")\n\t}\n\tif existing.Parameters.APIKey == \"\" {\n\t\treturn nil\n\t}\n\texisting.Parameters.APIKey = \"\"\n\tif err := s.repo.Update(ctx, existing); err != nil {\n\t\treturn err\n\t}\n\tlogger.Infof(ctx, \"WebSearch provider credential cleared by user: tenant=%d id=%s field=%s\", tenantID, id, field)\n\treturn nil\n}","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/web_search_provider.go#L85-L121","documentation":"ClearProviderCredential only supports the 'api_key' field; any other field name is rejected. This is the allowlist guard for the credential-clearing endpoint — unknown credential fields are not provider-specific parameters.","triggerScenarios":"Thrown at internal/application/service/web_search_provider.go:103 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass field=\"api_key\" (the only clearable credential)","Check the client UI sends the correct field name","Extend the allowlist only if new credential fields are added"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}