{"record":{"id":"72a05752f4a2081c","repo":"Tencent/WeKnora","slug":"register-stored-resource-w","errorCode":null,"errorMessage":"register stored resource: %w","messagePattern":"register stored resource: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/resource_catalog.go","lineNumber":82,"sourceCode":"\tphysical string,\n\ttenantID uint64,\n\tname string,\n\tsize int64,\n\ttemporary bool,\n\tcontentHash string,\n) (string, error) {\n\tkind, mimeType := resourceKind(name)\n\tref, err := s.catalog.Register(ctx, tenantID, physical, interfaces.ResourceRegistration{\n\t\tKind:         kind,\n\t\tMimeType:     mimeType,\n\t\tOriginalName: filepath.Base(name),\n\t\tSize:         size,\n\t\tContentHash:  contentHash,\n\t\tTemporary:    temporary,\n\t})\n\tif err != nil {\n\t\t_ = s.inner.DeleteFile(ctx, physical)\n\t\treturn \"\", fmt.Errorf(\"register stored resource: %w\", err)\n\t}\n\treturn ref, nil\n}\n\nfunc (s *resourceCatalogFileService) SaveFile(\n\tctx context.Context,\n\tfile *multipart.FileHeader,\n\ttenantID uint64,\n\tknowledgeID string,\n) (string, error) {\n\tphysical, err := s.inner.SaveFile(ctx, file, tenantID, knowledgeID)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tref, err := s.register(ctx, physical, tenantID, file.Filename, file.Size, false, \"\")\n\tif err != nil {\n\t\treturn \"\", err\n\t}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/resource_catalog.go#L64-L100","documentation":"resourceCatalogFileService wraps the storage service; after the inner service physically stores a file (SaveFile/SaveBytes/CopyFile), it calls s.catalog to register metadata. If registration fails, it compensates by deleting the physical file and returns this error. The stored data is rolled back; nothing persists.","triggerScenarios":"Catalog write failure (DB down, constraint violation, duplicate content-hash/ref, oversized metadata) right after the inner file service successfully stored the object.","commonSituations":"Database connection pool exhaustion or timeouts under load, unique constraint violations on content hash or resource ID, catalog migrations out of sync, transient network blips between object store and DB.","solutions":["Inspect the wrapped error to find the catalog (DB) root cause","Retry the Save operation — the failed physical object was already deleted, so no orphan","Check catalog table constraints/schema match what register writes (hash, size, temporary flags)","Ensure catalog DB connectivity and pool limits before bulk uploads"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := catalog.HealthCheck(ctx); err != nil { return fmt.Errorf(\"catalog unavailable: %w\", err) }","typeGuard":null,"tryCatchPattern":"ref, err := svc.SaveFile(ctx, r, knowledgeID)\nif err != nil && strings.Contains(err.Error(), \"register stored resource\") {\n    time.Sleep(backoff)\n    ref, err = svc.SaveFile(ctx, r, knowledgeID) // safe: physical object was rolled back\n}","preventionTips":["Ensure catalog DB connectivity before bulk uploads","Keep catalog schema/migrations in sync","Handle unique content-hash constraints idempotently","Wrap register+store in retryable units — the service already deletes orphans"],"tags":["storage","catalog","transaction","compensation"],"backgroundTag":"resource-registration-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}