tui-cs/Terminal.Gui · warning · ArgumentException

0 length lines are not supported

Error message

0 length lines are not supported

What it means

Thrown by the private helper GetLineEndOnDiffAxis when a line's length is exactly zero. Zero-length lines have no extent on the differing axis, so endpoint computation is undefined. It is an ArgumentException. In normal Exclude flow, zero-length exclusion lines and zero-length collection lines are filtered out before this helper runs, so this guard is effectively an internal invariant that should be unreachable through public API use.

Solutions

  1. Do not create StraightLine objects with Length == 0; use Length >= 1 or omit the line.
  2. Filter zero-length lines from your collection before calling LineCanvas/Exclude.
  3. If hit unexpectedly, file a bug: the public API is supposed to guard this.

Example fix

// before
canvas.AddLine(new StraightLine(start, 0, Orientation.Horizontal, style));

// after
if (length > 0)
    canvas.AddLine(new StraightLine(start, length, Orientation.Horizontal, style));
Defensive patterns

Strategy: validation

Validate before calling

lines = lines.Where(l => l.Length != 0);

Type guard

static bool HasNoZeroLengthLines(IEnumerable<StraightLine> lines) => lines.All(l => l.Length != 0);

Prevention

When it happens

Trigger: Directly causing a StraightLine with Length == 0 to reach endpoint computation. Under the public Exclude API this is guarded (length==0 returns early; collection lines with Length==0 are skipped), so it indicates either an internal bug or a future caller bypassing the guards.

Common situations: Constructing StraightLine instances with Length 0 and passing them into LineCanvas operations that compute endpoints; or a regression in the Exclude guard logic.

Related errors


AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13). Data as JSON: /api/errors/ce6bb97834f3da6e. Report an issue: GitHub.

Appendix: source

Thrown at Terminal.Gui/Drawing/LineCanvas/StraightLineExtensions.cs:190

    /// <summary>
    ///     <para>
    ///         Calculates the single digit point where a line ends on the differing axis i.e. the maximum (controlling for
    ///         negative lengths).
    ///     </para>
    ///     <para>
    ///         For lines with <see cref="Orientation.Horizontal"/> this is an x coordinate. For lines that are
    ///         <see cref="Orientation.Vertical"/> this is a y coordinate.
    ///     </para>
    /// </summary>
    /// <param name="start">Where the line starts</param>
    /// <param name="length">Length of the line</param>
    /// <param name="orientation">Orientation of the line</param>
    /// <returns>The maximum x or y (whichever is differing) point on the line, controlling for negative lengths. </returns>
    private static int GetLineEndOnDiffAxis (Point start, int length, Orientation orientation)
    {
        if (length == 0)
        {
            throw new ArgumentException (@"0 length lines are not supported", nameof (length));
        }

        int sub = length > 0 ? 1 : -1;

        if (orientation == Orientation.Vertical)
        {
            // Points on line differ by y
            return Math.Max (start.Y + length - sub, start.Y);
        }

        // Points on line differ by x
        return Math.Max (start.X + length - sub, start.X);
    }

    /// <summary>
    ///     <para>
    ///         Calculates the single digit point where a line starts on the differing axis i.e. the minimum (controlling for
    ///         negative lengths).

View on GitHub (pinned to 2e47b11478)