{"record":{"id":"69f741954468c979","repo":"Tencent/WeKnora","slug":"tenant-repository-is-required","errorCode":null,"errorMessage":"tenant repository is required","messagePattern":"tenant repository is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/weknoracloud.go","lineNumber":124,"sourceCode":"\t}\n\n\t// CredentialsConfig.Scan already attempts decryption.\n\t// If the AES key has rotated, Scan silently keeps the enc:v1:... blob.\n\tif strings.HasPrefix(creds.AppSecret, utils.EncPrefix) {\n\t\treturn &types.WeKnoraCloudStatusResult{\n\t\t\tHasModels:   true,\n\t\t\tNeedsReinit: true,\n\t\t\tReason:      \"WeKnoraCloud 凭证解密失败（服务重启后加密密钥已变更），请重新填写 APPID 和 APPSECRET\",\n\t\t}, nil\n\t}\n\n\treturn &types.WeKnoraCloudStatusResult{HasModels: true, NeedsReinit: false}, nil\n}\n\n// updateTenantCredentials 更新空间的 WeKnoraCloud 凭证\nfunc (s *weKnoraCloudService) updateTenantCredentials(ctx context.Context, tenantID uint64, appID, appSecret string) error {\n\tif s.tenantRepo == nil {\n\t\treturn fmt.Errorf(\"tenant repository is required\")\n\t}\n\n\ttenant, err := s.tenantRepo.GetTenantByID(ctx, tenantID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif tenant.Credentials == nil {\n\t\ttenant.Credentials = &types.CredentialsConfig{}\n\t}\n\ttenant.Credentials.WeKnoraCloud = &types.WeKnoraCloudCredentials{\n\t\tAppID:     appID,\n\t\tAppSecret: appSecret,\n\t}\n\treturn s.tenantRepo.UpdateTenant(ctx, tenant)\n}\n","sourceCodeStart":106,"sourceCodeEnd":140,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/weknoracloud.go#L106-L140","documentation":"updateTenantCredentials guards that the injected tenant repository is non-nil before persisting WeKnoraCloud credentials. A nil repo means the service was mis-constructed (dependency wiring bug), not a user-input problem.","triggerScenarios":"Thrown at internal/application/service/weknoracloud.go:124 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inject the tenant repository when constructing weKnoraCloudService","Check DI/initialization wiring for the service","Treat as a deployment bug; fail the credential save"],"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"}