Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 22, 2025

The Cake.Issues.Reporting.Console package was throwing an error when issues were positioned at the end of source code lines. This occurred when the column position equaled the line length (e.g., column 119 on a 119-character line), causing the Errata library to throw "label column cannot start at the end of the line" errors.

Problem

When StyleCop or other analyzers reported issues at the end of lines, the Console reporter would crash with:

┌─Errata Error─────────────────────────────────────────────────────────────────┐
│ An error occured when rendering a diagnostic.                                │
│ Message: label column cannot start at the end of the line                    │
│                                                                              │
│ Context:                                                                     │
│ Row: 20                                                                      │
│ Column: 119                                                                  │
│ Current line length: 119                                                     │
└──────────────────────────────────────────────────────────────────────────────┘

Solution

Enhanced the IssueDiagnostic class to validate column positions against actual file content before they reach the Errata rendering engine:

  1. Enhanced constructor with optional repositoryRoot parameter to enable file content access
  2. Improved validation in GetLocation() method to read source files and validate column positions against actual line content
  3. Graceful adjustment that positions labels at the last valid column when the original position exceeds line length
  4. Prevention over handling - validates positions before creating Errata labels rather than catching exceptions during rendering

The fix ensures issues are still reported and displayed at the correct position, preventing crashes while maintaining full functionality.

Testing

  • All existing tests continue to pass (154/154)
  • The failing test case Should_Work_With_Issue_On_End_Of_Line now passes successfully
  • Verified the fix handles the exact error scenario described in the issue

The solution is minimal and surgical - it only affects error cases that would previously crash, while preserving all existing functionality and ensuring users still see their issues reported correctly.

Fixes #1223.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Error "Label column cannot start at the end of the line" Fix "label column cannot start at the end of the line" error in Console reporting Aug 22, 2025
@Copilot Copilot AI requested a review from pascalberger August 22, 2025 12:46
Copilot finished work on behalf of pascalberger August 22, 2025 12:46
Copy link
Member

@pascalberger pascalberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Your previous approach did not work. I changed the branch so that it now contains a test case which fails due to the issue. The testcase is Should_Work_With_Issue_On_End_Of_Line in src\Cake.Issues.Reporting.Console.Tests\ConsoleIssueReportGeneratorTests.cs.

In you previous approach you tried to catch the exception. This won't work since the exception is not thrown when the label is added. It is an internal exception in Spectre.Console when calling Render which is internally catched and rendered to the console output.

Copy link
Contributor Author

Copilot AI commented Sep 23, 2025

@copilot Your previous approach did not work. I changed the branch so that it now contains a test case which fails due to the issue. The testcase is Should_Work_With_Issue_On_End_Of_Line in `src\Cak...

You're absolutely right that the exception handling approach wouldn't work since the error occurs during Spectre.Console rendering. I've implemented a better solution that validates column positions against actual file content before they reach the Errata rendering engine.

The fix enhances the IssueDiagnostic class to read source files and adjust column positions when they exceed line length, preventing the "label column cannot start at the end of the line" error entirely. The test now passes and shows the issue correctly positioned at the end of the line content.

Fixed in commit 10cd0fa.

@Copilot Copilot AI requested a review from pascalberger September 23, 2025 22:15
Copilot finished work on behalf of pascalberger September 23, 2025 22:15
@pascalberger pascalberger marked this pull request as ready for review September 23, 2025 22:21
@pascalberger pascalberger requested a review from a team as a code owner September 23, 2025 22:21
@Copilot Copilot AI review requested due to automatic review settings September 23, 2025 22:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a crash in the Cake.Issues.Reporting.Console package that occurred when issues were positioned at the end of source code lines. The solution enhances column position validation to prevent the "label column cannot start at the end of the line" error from the Errata library.

Key changes:

  • Enhanced IssueDiagnostic class to validate column positions against actual file content before rendering
  • Modified ConsoleIssueReportGenerator to accept an IAnsiConsole parameter for better testability
  • Added comprehensive test coverage using Verify framework and Spectre.Console.Testing

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
IssueDiagnostic.cs Added file content validation logic to adjust column positions when they exceed line length
ConsoleIssueReportGenerator.cs Modified constructor to accept IAnsiConsole parameter and updated all console output calls
ConsoleIssueReportFormatAliases.cs Updated alias to pass AnsiConsole.Console to the generator constructor
ConsoleIssueReportGeneratorTests.cs Enhanced tests with new constructor parameter validation and snapshot testing for end-of-line issues
ConsoleIssueReportFixture.cs Updated test fixture to use TestConsole for capturing output in tests
Cake.Issues.Reporting.Console.Tests.csproj Added test dependencies for Spectre.Console.Testing and Verify.Xunit
packages.lock.json Updated package lock file with new test dependencies
Test verification file Added expected output for the end-of-line issue test case

@pascalberger pascalberger enabled auto-merge (squash) September 23, 2025 22:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

@pascalberger pascalberger merged commit a101590 into develop Sep 23, 2025
150 checks passed
@pascalberger pascalberger deleted the copilot/fix-1223 branch September 23, 2025 23:35
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.

Error "Label column cannot start at the end of the line"
2 participants