Skip to content

Fix crash in SegmentShape.Calculate when lines list is empty#2036

Merged
patriksvensson merged 2 commits intospectreconsole:mainfrom
rodrigomfvn:segmentshape-calculate-throws-when-no-lines
Mar 3, 2026
Merged

Fix crash in SegmentShape.Calculate when lines list is empty#2036
patriksvensson merged 2 commits intospectreconsole:mainfrom
rodrigomfvn:segmentshape-calculate-throws-when-no-lines

Conversation

@rodrigomfvn
Copy link
Copy Markdown
Contributor

Fixes #2015

  • I have read the Contribution Guidelines
  • I have checked that there isn't already another pull request that solves the above issue
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors

Changes

  • Adds a unit test verifying that SegmentShape.Calculate returns a zero size when called with an empty lines collection.
  • Prevents an InvalidOperationException caused by calling Enumerable.Max on an empty list.
  • Returns a width of 0 when lines is empty instead of throwing.

This ensures that rendering an empty Table with hidden headers does not crash during Live rendering.


Please upvote 👍 this pull request if you are interested in it.

Adds a unit test to verify that SegmentShape.Calculate returns a zero size when called with an empty lines collection.

This test reproduces a bug where an InvalidOperationException was thrown due to calling Enumerable.Max on an empty collection.
Prevents InvalidOperationException when SegmentShape.Calculate is called with an empty lines list.

Checks if lines.Count are greater than 0 before calling Enumerable.Max, returning width 0 if the list is empty.

Fixes #2015
@rodrigomfvn
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@patriksvensson patriksvensson merged commit 17f63d5 into spectreconsole:main Mar 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvalidOperationException in SegmentShape.Calculate when rendering an empty Table with hidden headers

2 participants