{"record":{"id":"f32665d10c5bf6cf","repo":"Tencent/WeKnora","slug":"bind-copied-resource-w","errorCode":null,"errorMessage":"bind copied resource: %w","messagePattern":"bind copied resource: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/resource_catalog.go","lineNumber":188,"sourceCode":"\ttenantID uint64,\n\tknowledgeID string,\n) (string, error) {\n\tphysical, _, err := s.resolve(ctx, filePath)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tcopied, err := s.inner.CopyFile(ctx, physical, tenantID, knowledgeID)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tref, err := s.register(ctx, copied, tenantID, filepath.Base(physical), 0, false, \"\")\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif knowledgeID != \"\" {\n\t\tif err := s.catalog.Bind(ctx, ref, types.ResourceOwnerKnowledge, knowledgeID, types.ResourceRelationSourceFile); err != nil {\n\t\t\t_ = s.DeleteFile(ctx, ref)\n\t\t\treturn \"\", fmt.Errorf(\"bind copied resource: %w\", err)\n\t\t}\n\t}\n\treturn ref, nil\n}\n\nvar _ interfaces.FileService = (*resourceCatalogFileService)(nil)\n","sourceCodeStart":170,"sourceCodeEnd":195,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/resource_catalog.go#L170-L195","documentation":"In CopyFile, after the copy is stored and registered, an optional knowledgeID triggers catalog.Bind to attach the copied resource to a knowledge entry. On Bind failure the newly copied resource is deleted (rollback) and this wrapped error is returned. The copy is fully discarded; retry the entire CopyFile.","triggerScenarios":"Calling CopyFile with a non-empty knowledgeID where the knowledge entry is missing, concurrently deleted, or the catalog DB insert fails (constraint, connection loss).","commonSituations":"Copying files into knowledge bases that were deleted in another session, DB deadlocks/constraints during bulk copies, stale client-side knowledge IDs.","solutions":["Validate the knowledgeID exists before CopyFile","Read the wrapped error for the DB-level cause","Retry the whole CopyFile — the rolled-back copy leaves no orphans","Skip binding (empty knowledgeID) if the link is optional"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if knowledgeID != \"\" && !catalog.KnowledgeExists(ctx, knowledgeID) {\n    return fmt.Errorf(\"knowledge %q does not exist\", knowledgeID)\n}","typeGuard":null,"tryCatchPattern":"ref, err := svc.CopyFile(ctx, src, knowledgeID)\nif err != nil && strings.Contains(err.Error(), \"bind copied resource\") {\n    // copy was rolled back; re-validate knowledgeID and retry the copy\n}","preventionTips":["Validate the target knowledge entry before copying","Serialize copy operations against knowledge deletions","Treat the whole CopyFile as the retry unit","Return/refresh knowledge IDs rather than reusing stale ones"],"tags":["catalog","bind","copy","rollback"],"backgroundTag":"resource-bind-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}