Skip to content

Fix console logs clear not going back to a blank state #9910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2025

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Jun 17, 2025

Description

Fix this error:

System.InvalidOperationException: Cannot access index 0. Buffer size is 0
at Aspire.Hosting.ConsoleLogs.LogEntries.<InsertSortedCore>g__InsertAt|15_0(Int32 index, <>c__DisplayClass15_0&) in /_/src/Shared/ConsoleLogs/LogEntries.cs:line 190
   at Aspire.Hosting.ConsoleLogs.LogEntries.InsertSortedCore(LogEntry logEntry) in /_/src/Shared/ConsoleLogs/LogEntries.cs:line 162
   at Aspire.Dashboard.Components.Pages.ConsoleLogs.<>c__DisplayClass124_0.<<LoadLogs>b__0>d.MoveNext() in /_/src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs:line 536
--- End of stack trace from previous location ---
   at Aspire.Dashboard.Components.Pages.ConsoleLogs.<>c__DisplayClass124_0.<<LoadLogs>b__0>d.MoveNext() in /_/src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs:line 508
--- End of stack trace from previous location ---
   at Aspire.Dashboard.Components.Pages.ConsoleLogs.<>c__DisplayClass124_0.<<LoadLogs>b__0>d.MoveNext() in /_/src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs:line 552
--- End of stack trace from previous location ---
   at Aspire.Dashboard.Utils....

If a user have the right sequence of log values, then clears the logs, then gets a new log value, they can get this error.

Contributes to #9537

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 05:48
Copy link
Contributor

@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 ensures that calling Clear on LogEntries resets the earliest timestamp index so the buffer truly returns to an empty state and adds a unit test to verify this behavior.

  • Reset _earliestTimestampIndex in Clear
  • Add Clear_AfterEarliestTimestampIndex_Success test

Reviewed Changes

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

File Description
tests/Aspire.Dashboard.Tests/ConsoleLogsTests/LogEntriesTests.cs Added a test to verify that Clear resets timestamp state
src/Shared/ConsoleLogs/LogEntries.cs Null out _earliestTimestampIndex during Clear
Comments suppressed due to low confidence (2)

src/Shared/ConsoleLogs/LogEntries.cs:56

  • The Clear method resets BaseLineNumber and _earliestTimestampIndex but does not actually clear the internal entries list. Consider calling _entries.Clear() (while preserving active pause entries if needed) to fully reset the buffer.
BaseLineNumber = null;

tests/Aspire.Dashboard.Tests/ConsoleLogsTests/LogEntriesTests.cs:27

  • [nitpick] The test name is a bit vague. Rename it to something like Clear_ResetsEarliestTimestampIndex_AndClearsEntries to clearly convey both behaviors being verified.
public void Clear_AfterEarliestTimestampIndex_Success()

@JamesNK JamesNK requested review from mitchdenny and adamint June 17, 2025 22:39
@JamesNK JamesNK merged commit aa67b3f into main Jun 19, 2025
496 of 498 checks passed
@JamesNK JamesNK deleted the jamesnk/fix-consolelogs-test branch June 19, 2025 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants