Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Fix chart showing No Data on rapid period switching#1816

Merged
DRadmir merged 3 commits into
mainfrom
fix-chart-no-data-on-period-switch
Mar 23, 2026
Merged

Fix chart showing No Data on rapid period switching#1816
DRadmir merged 3 commits into
mainfrom
fix-chart-no-data-on-period-switch

Conversation

@DRadmir
Copy link
Copy Markdown
Contributor

@DRadmir DRadmir commented Mar 23, 2026

Ignore cancelled task errors instead of setting error state

Ignore cancelled task errors instead of setting error state
@DRadmir DRadmir self-assigned this Mar 23, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of chart and portfolio data loading by implementing cooperative task cancellation. The changes ensure that when a user rapidly changes the selected period, previous, now-irrelevant data fetching tasks are properly cancelled and their potential errors are ignored, preventing the UI from showing incorrect 'No Data' or error messages and providing a smoother user experience.

Highlights

  • Improved Chart Stability: Introduced cooperative task cancellation checks to prevent charts from displaying 'No Data' or error states when users rapidly switch between time periods.
  • Graceful Error Handling: Modified error handling logic in data fetching operations to ignore CancellationErrors, ensuring that cancelled tasks do not inadvertently trigger an error state in the UI.
  • Consistent Cancellation Logic: Applied the new cancellation handling pattern across ChartSceneViewModel, PerpetualPortfolioSceneViewModel, and WalletPortfolioSceneViewModel for uniform behavior.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue where charts show 'No Data' during rapid period switching by ignoring errors from cancelled tasks. The approach of adding cancellation points with Task.checkCancellation() and handling cancellation in catch blocks is correct. However, the implementation can be made more robust. Instead of checking Task.isCancelled, it's safer to specifically check if the caught error is a CancellationError. This prevents accidentally swallowing other legitimate errors that might occur while the task is in a cancelled state. I've added suggestions to make this change in all affected files.

)
chartState = .data(model)
} catch {
guard !Task.isCancelled else { return }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While checking Task.isCancelled works for the intended purpose of ignoring cancellation errors, it can lead to swallowing non-cancellation errors if the task happens to be cancelled when another error is thrown. A more robust approach is to check if the caught error is specifically a CancellationError.

Suggested change
guard !Task.isCancelled else { return }
guard !(error is CancellationError) else { return }

}
state = .data(data)
} catch {
guard !Task.isCancelled else { return }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While checking Task.isCancelled works for the intended purpose of ignoring cancellation errors, it can lead to swallowing non-cancellation errors if the task happens to be cancelled when another error is thrown. A more robust approach is to check if the caught error is specifically a CancellationError.

Suggested change
guard !Task.isCancelled else { return }
guard !(error is CancellationError) else { return }

let chart = ChartValuesViewModel.priceChange(charts: charts, period: selectedPeriod, formatter: currencyFormatter, showHeaderValue: true)
state = chart.map { .data(WalletPortfolioData(chart: $0, portfolio: portfolio)) } ?? .noData
} catch {
guard !Task.isCancelled else { return }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While checking Task.isCancelled works for the intended purpose of ignoring cancellation errors, it can lead to swallowing non-cancellation errors if the task happens to be cancelled when another error is thrown. A more robust approach is to check if the caught error is specifically a CancellationError.

Suggested change
guard !Task.isCancelled else { return }
guard !(error is CancellationError) else { return }

assetId: assetModel.asset.id,
period: selectedPeriod
)
try Task.checkCancellation()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

try Task.checkCancellation() is unnecessary in here - task(id:) already propagates cancellation through try await

state = .loading
do {
let data = try await perpetualService.portfolio(address: address)
try Task.checkCancellation()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here

do {
let rate = try priceService.getRate(currency: currencyCode)
let portfolio = try await service.getPortfolioAssets(assets: assets, period: selectedPeriod)
try Task.checkCancellation()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here

)
chartState = .data(model)
} catch {
guard !Task.isCancelled else { return }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lets use for consistency?

if !error.isCancelled {
chartState = .error(error)
}

@gemdev111 gemdev111 self-requested a review March 23, 2026 18:43
Extract cancellation-aware error handling into a reusable setError method on StateViewType, replacing manual `if !error.isCancelled` checks across 10 call sites.
@DRadmir DRadmir merged commit a5c8f97 into main Mar 23, 2026
1 check passed
@DRadmir DRadmir deleted the fix-chart-no-data-on-period-switch branch March 23, 2026 19:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants