spectreconsole/spectre.console · error · InvalidOperationException

Task name cannot be empty.

Error message

Task name cannot be empty.

What it means

Thrown by the internal ProgressTask.Update method when the description parameter is non-null but becomes empty after RemoveNewLines and Trim. Update is called by the public Description setter (and Increment/UpdateValue). Unlike the constructor (which throws ArgumentException), this path throws InvalidOperationException. The check ensures a task's description can never become blank after construction.

Source

Thrown at src/Spectre.Console/Live/Progress/ProgressTask.cs:216

    /// </summary>
    public int MaxSamplesKept { get; set; } = 1000;

    private void Update(
        string? description = null,
        double? maxValue = null,
        double? increment = null,
        double? value = null)
    {
        lock (_lock)
        {
            var startValue = Value;

            if (description != null)
            {
                description = description?.RemoveNewLines()?.Trim();
                if (string.IsNullOrWhiteSpace(description))
                {
                    throw new InvalidOperationException("Task name cannot be empty.");
                }

                _description = description;
            }

            if (maxValue != null)
            {
                _maxValue = maxValue.Value;
            }

            if (increment != null)
            {
                _value += increment.Value;
            }

            if (value != null)
            {
                _value = value.Value;

View on GitHub (pinned to 0acc92fada)

Solutions

  1. Validate non-whitespace before assigning task.Description.
  2. Keep the old description if the new one is empty: if (!string.IsNullOrWhiteSpace(newDesc)) task.Description = newDesc;
  3. Sanitize upstream data so blank strings never reach the Description setter.

Example fix

// before
task.Description = newName; // newName may be "   "

// after
if (!string.IsNullOrWhiteSpace(newName))
{
    task.Description = newName;
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate before updating description
if (!string.IsNullOrWhiteSpace(newDescription))
{
    task.Description = newDescription;
}

Type guard

static bool IsValidTaskDescription(string? description)
    => !string.IsNullOrWhiteSpace(description);

Prevention

When it happens

Trigger: Setting task.Description = " " or task.Description = ""; calling any API that delegates to Update with a whitespace-only description string. This includes ProgressTask.Increment when description is passed, though Increment only passes increment.

Common situations: Dynamically updating a task description from live data that becomes empty; user input or config driving Description that wasn't sanitized; clearing a description intentionally (not supported by design).

Related errors


AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13). Data as JSON: /api/errors/477e7c41d8d0c9ee. Report an issue: GitHub.