vxcontrol/pentagi · error
failed to delete destination for overwrite
Error message
failed to delete destination for overwrite: %w
What it means
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.
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
Defensive patterns
Strategy: try-catch
Validate before calling
if dest, ok := findResourceByPath(dst); ok && !dest.IsDir && force {
// consider warning user about destructive overwrite
} Try / catch
err := svc.MoveResource(ctx, uid, src, dst, true)
var wrapped error
if errors.As(err, &wrapped) && strings.Contains(err.Error(), "failed to delete destination") {
log.Printf("overwrite delete failed: %v", err) // inspect cause, retry
} Prevention
- Add ON DELETE CASCADE on tables referencing user_resources
- Monitor DB connectivity for mid-transaction drops
- Avoid concurrent writes to the same resource subtree
When it happens
Trigger: 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.
Common situations: Concurrent flows referencing the destination resource row; database connectivity issues mid-transaction; missing ON DELETE CASCADE on tables referencing user_resources.
Related errors
- failed to delete merged source directory
- failed to delete source directory
- failed to check destination conflicts
- failed to copy resource
- failed to copy resource
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/aee7a60d9bbf2676.
Report an issue: GitHub.
Appendix: source
Thrown at backend/pkg/server/services/resources.go:911
} else {
createdDirs, deletedDirs, orphanHashes, err := ensureResourceDirs(tx, uid, resources.ParentDir(targetPath), force)
if err != nil {
return result, err
}
result.Added = append(result.Added, convertResources(createdDirs)...)
result.DeletedBefore = append(result.DeletedBefore, convertResources(deletedDirs)...)
result.OrphanHashes = append(result.OrphanHashes, orphanHashes...)
}
if exists {
if dest.IsDir {
return result, errResourceConflict
}
if !force {
return result, errResourceConflict
}
if err := tx.Delete(&dest).Error; err != nil {
return result, fmt.Errorf("failed to delete destination for overwrite: %w", err)
}
result.DeletedBefore = append(result.DeletedBefore, convertResource(dest))
if dest.Hash != "" {
result.OrphanHashes = append(result.OrphanHashes, dest.Hash)
}
}
updated, err := updateMovedResource(tx, src, targetPath, time.Now())
if err != nil {
return result, err
}
result.Updated = append(result.Updated, convertResource(updated))
return result, nil
}
func (s *ResourceService) moveDirResource(
tx *gorm.DB,
uid uint64,View on GitHub (pinned to ea665308ba)