spectreconsole/spectre.console · error · ArgumentException
Task name cannot be empty
Error message
Task name cannot be empty
What it means
Thrown by the ProgressTask constructor when the description parameter, after RemoveNewLines and Trim, is null or whitespace. The null check on description itself throws ArgumentNullException separately; this ArgumentException fires when description is a non-null string that becomes empty after trimming (e.g., " ", "\n\t", or ""). Every ProgressTask must have a visible, non-empty description for rendering.
Source
Thrown at src/Spectre.Console/Live/Progress/ProgressTask.cs:142
/// </summary>
/// <param name="id">The task ID.</param>
/// <param name="description">The task description.</param>
/// <param name="maxValue">The task max value.</param>
/// <param name="autoStart">Whether or not the task should start automatically.</param>
/// <param name="timeProvider">The time provider to use. Defaults to <see cref="TimeProvider.System"/>.</param>
public ProgressTask(int id, string description, double maxValue, bool autoStart = true, TimeProvider? timeProvider = null)
{
lazySamples = new(() => new CircularBuffer<ProgressSample>(MaxSamplesKept) { UniqueRemovedCheck = false });
_lock = new object();
_timeProvider = timeProvider ?? TimeProvider.System;
_maxValue = maxValue;
_value = 0;
_description = description?.RemoveNewLines()?.Trim() ??
throw new ArgumentNullException(nameof(description));
if (string.IsNullOrWhiteSpace(_description))
{
throw new ArgumentException("Task name cannot be empty", nameof(description));
}
Id = id;
State = new ProgressTaskState();
StartTime = autoStart ? _timeProvider.GetLocalNow().LocalDateTime : null;
}
/// <summary>
/// Starts the task.
/// </summary>
public void StartTask()
{
lock (_lock)
{
if (StopTime != null)
{
throw new InvalidOperationException("Stopped tasks cannot be restarted");
}View on GitHub (pinned to 0acc92fada)
Solutions
- Validate the description string is non-whitespace before constructing the ProgressTask or calling AddTask.
- Provide a fallback description when the source data is empty: var desc = string.IsNullOrWhiteSpace(name) ? "Unnamed task" : name;
- Sanitize input upstream so empty descriptions never reach the progress API.
Example fix
// before var task = ctx.AddTask(userInput); // userInput may be " " // after var desc = string.IsNullOrWhiteSpace(userInput) ? "Processing" : userInput; var task = ctx.AddTask(desc);
Defensive patterns
Strategy: validation
Validate before calling
// Sanitize description before creating task
var desc = string.IsNullOrWhiteSpace(description)
? "Unnamed task"
: description.Trim();
var task = new ProgressTask(id, desc, maxValue); Type guard
static bool IsValidTaskDescription(string? description)
=> !string.IsNullOrWhiteSpace(description); Prevention
- Validate description for non-whitespace before AddTask or new ProgressTask.
- Provide a fallback name when the source data is empty.
- Sanitize user input upstream so blank strings never reach the progress API.
When it happens
Trigger: Creating new ProgressTask(id, " ", 100) or new ProgressTask(id, "", 100); also new ProgressTask(id, "\n\n", 100). Calling AnsiConsole.Progress().Start(ctx => ctx.AddTask(" ")) hits this same constructor.
Common situations: Description sourced from user input, config, or data that wasn't validated for whitespace; dynamically generated names from data that produces empty strings; copy-paste leaving a placeholder empty string in AddTask.
Related errors
- Task name cannot be empty.
- Stopped tasks cannot be restarted
- Array does not contain enough space for items
- At least one column must be specified.
- Invalid Figlet font
AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13).
Data as JSON: /api/errors/41b38c531e6d0f80.
Report an issue: GitHub.