Skip to content

ProgressTask accepts negative MaxValue without validation #2167

Description

@MateusMo

Information

  • OS: Ubuntu 24.04
  • Version: main (current branch)
  • Terminal: GNOME Terminal

Describe the issue

While exploring the progress API, I noticed that AddTask accepts a negative maxValue without any validation.

For example:

using Spectre.Console;

AnsiConsole.Progress()
    .Start(ctx =>
    {
        var task = ctx.AddTask("Loading World Map", true, -1);

        while (!ctx.IsFinished)
        {
            task.Increment(1);
            Thread.Sleep(50);
        }
    });

The task completes immediately and the progress output appears inconsistent.

While looking through the implementation, I noticed that GetPercentage() explicitly handles MaxValue == 0, but there doesn't seem to be any validation preventing negative values from being passed.

I'm not sure whether accepting negative values is intentional or if they should be rejected (for example by throwing ArgumentOutOfRangeException).

Expected behavior

If negative MaxValue values are not supported, it might be better to validate the argument early instead of allowing the task to enter an inconsistent state.

If this is considered a bug and the proposed direction makes sense, I'd be happy to work on a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageSomeone needs to take a look at this

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions