fullstackhero/dotnet-starter-kit · error · CustomException

Cannot change visibility while file is in status

Error message

Cannot change visibility while file is in status {Status}.

What it means

FileAsset.ChangeVisibility is only allowed while the asset is Available; in any other status (PendingUpload, Quarantined, deleted/archived per the model) it throws CustomException with 409 Conflict. The doc comment notes visibility URLs are only well-defined for available files.

Solutions

  1. Only offer the visibility toggle for files with status Available in the UI.
  2. On 409, refetch the asset and show its current status to the user.
  3. Wait for scan completion (poll or realtime update) before allowing visibility changes.
  4. Do not attempt visibility changes on quarantined files — that state is intentionally locked.

Example fix

// before
await api.patch(`/files/${id}/visibility`, { visibility: 'Public' }); // 409 if quarantined
// after
const asset = await api.get(`/files/${id}`);
if (asset.status !== 'Available') { showStatus(asset.status); return; }
await api.patch(`/files/${id}/visibility`, { visibility: 'Public' });
Defensive patterns

Strategy: type-guard

Validate before calling

const asset = await api.get(`/files/${id}`);
if (asset.status !== 'Available') { showStatus(asset.status); return; }

Type guard

const canChangeVisibility = (a: FileAsset): a is FileAsset & { status: 'Available' } => a.status === 'Available';

Try / catch

try { await api.patch(`/files/${id}/visibility`, { visibility }); }
catch (e) { if (isConflict(e)) { await refreshAsset(id); } else { throw e; } }

Prevention

When it happens

Trigger: Calling the change-visibility endpoint on a file still awaiting upload completion, on a quarantined (infected) file, or on an asset whose status was otherwise advanced.

Common situations: User toggles public/private from a stale list while the upload is still in progress; attempting to share a quarantined file; UI not refreshing status after a scan job moved the asset.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of fullstackhero/dotnet-starter-kit@3f2959e683 (2026-09-15). Data as JSON: /api/errors/9cc2c5e0784be91f. Report an issue: GitHub.

Appendix: source

Thrown at src/Modules/Files/Modules.Files/Domain/FileAsset.cs:126

    public void Restore()
    {
        if (!IsDeleted) return;
        IsDeleted = false;
        DeletedOnUtc = null;
        DeletedBy = null;
        UpdatedAtUtc = DateTime.UtcNow;
    }

    /// <summary>
    /// Flip the file's <see cref="Visibility"/> after upload. Idempotent. Refuses to mutate
    /// files that haven't finished uploading or are quarantined — those are not in a state
    /// where the URL contract is well-defined.
    /// </summary>
    public void ChangeVisibility(Visibility next)
    {
        if (Status != FileAssetStatus.Available)
        {
            throw new CustomException(
                $"Cannot change visibility while file is in status {Status}.",
                errors: null,
                HttpStatusCode.Conflict);
        }
        if (Visibility == next) return;
        Visibility = next;
        UpdatedAtUtc = DateTime.UtcNow;
    }
}

View on GitHub (pinned to 3f2959e683)