{"record":{"id":"aee7a60d9bbf2676","repo":"vxcontrol/pentagi","slug":"failed-to-delete-destination-for-overwrite-w","errorCode":null,"errorMessage":"failed to delete destination for overwrite: %w","messagePattern":"failed to delete destination for overwrite: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"backend/pkg/server/services/resources.go","lineNumber":911,"sourceCode":"\t} else {\n\t\tcreatedDirs, deletedDirs, orphanHashes, err := ensureResourceDirs(tx, uid, resources.ParentDir(targetPath), force)\n\t\tif err != nil {\n\t\t\treturn result, err\n\t\t}\n\t\tresult.Added = append(result.Added, convertResources(createdDirs)...)\n\t\tresult.DeletedBefore = append(result.DeletedBefore, convertResources(deletedDirs)...)\n\t\tresult.OrphanHashes = append(result.OrphanHashes, orphanHashes...)\n\t}\n\n\tif exists {\n\t\tif dest.IsDir {\n\t\t\treturn result, errResourceConflict\n\t\t}\n\t\tif !force {\n\t\t\treturn result, errResourceConflict\n\t\t}\n\t\tif err := tx.Delete(&dest).Error; err != nil {\n\t\t\treturn result, fmt.Errorf(\"failed to delete destination for overwrite: %w\", err)\n\t\t}\n\t\tresult.DeletedBefore = append(result.DeletedBefore, convertResource(dest))\n\t\tif dest.Hash != \"\" {\n\t\t\tresult.OrphanHashes = append(result.OrphanHashes, dest.Hash)\n\t\t}\n\t}\n\n\tupdated, err := updateMovedResource(tx, src, targetPath, time.Now())\n\tif err != nil {\n\t\treturn result, err\n\t}\n\tresult.Updated = append(result.Updated, convertResource(updated))\n\treturn result, nil\n}\n\nfunc (s *ResourceService) moveDirResource(\n\ttx *gorm.DB,\n\tuid uint64,","sourceCodeStart":893,"sourceCodeEnd":929,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/server/services/resources.go#L893-L929","documentation":"moveFileResource deletes an existing destination file when overwriting (force=true) after conflict checks pass. This error wraps the underlying GORM/DB error from tx.Delete, meaning the overwrite could not be performed because the destination row failed to delete. The transaction returns with the error so it is rolled back.","triggerScenarios":"Moving a file onto an existing file with force=true while the DB delete of the destination row fails — e.g. foreign-key constraint on the destination resource, DB connection drop, or lock contention on the row.","commonSituations":"Concurrent flows referencing the destination resource row; database connectivity issues mid-transaction; missing ON DELETE CASCADE on tables referencing user_resources.","solutions":["Inspect the wrapped error for the root DB cause (constraint name, connection error)","Check for foreign keys referencing user_resources and ensure ON DELETE CASCADE","Retry the move after the transient DB issue resolves; conflicts on rows are serialized by the transaction"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if dest, ok := findResourceByPath(dst); ok && !dest.IsDir && force {\n    // consider warning user about destructive overwrite\n}","typeGuard":null,"tryCatchPattern":"err := svc.MoveResource(ctx, uid, src, dst, true)\nvar wrapped error\nif errors.As(err, &wrapped) && strings.Contains(err.Error(), \"failed to delete destination\") {\n    log.Printf(\"overwrite delete failed: %v\", err) // inspect cause, retry\n}","preventionTips":["Add ON DELETE CASCADE on tables referencing user_resources","Monitor DB connectivity for mid-transaction drops","Avoid concurrent writes to the same resource subtree"],"tags":["database","gorm","delete","overwrite"],"backgroundTag":"database-delete-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}