Skip to content

fix: remove async from void onPress callback (SonarCloud bug)#174

Open
alichherawalla wants to merge 2 commits into
mainfrom
fix/sonar-async-void-onpress
Open

fix: remove async from void onPress callback (SonarCloud bug)#174
alichherawalla wants to merge 2 commits into
mainfrom
fix/sonar-async-void-onpress

Conversation

@alichherawalla
Copy link
Copy Markdown
Owner

Summary

  • Removes async/await from the delete server onPress callback in RemoteServersScreen
  • SonarCloud flagged this as a bug: Promise-returning function provided where () => void was expected
  • removeServer is fire-and-forget in this context, so dropping async is safe

Test plan

  • All JS/TS tests pass
  • Android unit tests pass
  • iOS unit tests pass
  • Verify SonarCloud quality gate passes after merge

🤖 Generated with Claude Code

SonarCloud flagged a Promise-returning function passed to onPress which
expects () => void. Dropping async/await since removeServer is
fire-and-forget in this context.

Authored-by: GLM <work@wednesday.is>
@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 resolves a SonarCloud quality gate issue by refactoring a server deletion callback. The change ensures that an onPress handler, which expects a void return, no longer incorrectly uses async/await for an operation that does not require awaiting its completion in this specific UI context, thereby improving code quality and adherence to best practices.

Highlights

  • SonarCloud Bug Fix: Removed async/await from the onPress callback for deleting a server in RemoteServersScreen to resolve a SonarCloud warning.
  • Callback Signature Alignment: Addressed a SonarCloud flag where a promise-returning function was provided when a () => void signature was expected for the onPress callback.
  • Fire-and-Forget Operation: Confirmed that the removeServer operation is a fire-and-forget action in this context, making the removal of async/await safe and appropriate.
Activity
  • Generated with Claude Code.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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 fixes a SonarCloud bug by removing async/await from an onPress callback, which expects a void returning function. However, this change introduces an unhandled promise, which could lead to silent failures if the server deletion process fails. I've kept the review comment with a suggestion to properly handle promise rejections by adding a .catch() block, which aligns with the project's general rules and improves error handling.

Comment on lines +107 to 110
onPress: () => {
if (activeServerId === server.id) setActiveServerId(null);
await remoteServerManager.removeServer(server.id);
remoteServerManager.removeServer(server.id);
},
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.

high

While removing async/await fixes the SonarCloud issue with the onPress function signature, it introduces a potential for silent failures. The removeServer function is async and can reject (e.g., if deleting the API key from the keychain fails). By not handling the returned promise, any rejection will be swallowed, and the user won't know the deletion failed.

This violates a general project rule: "Use .catch() to handle promise rejections instead."

To fix this, you should add a .catch() block to handle potential errors and inform the user, for example by showing another alert.

          onPress: () => {
            if (activeServerId === server.id) setActiveServerId(null);
            remoteServerManager.removeServer(server.id).catch(error =>
              setAlertState(showAlert('Deletion Failed', error instanceof Error ? error.message : 'An unknown error occurred.'))
            );
          },
References
  1. Avoid using the void operator for unawaited promises to adhere to the project's no-void ESLint rule. Use .catch() to handle promise rejections instead.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Good catch — added .catch() with an error alert so the user sees a "Deletion Failed" message if removeServer rejects. Pushed in 489ebc8.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 14, 2026

Greptile Summary

This PR removes async/await from the delete server onPress callback in RemoteServersScreen to fix a SonarCloud bug where a Promise-returning function was provided where () => void was expected. The fix is correct and safe — the behavior was already effectively fire-and-forget before (the caller discarded the Promise regardless).

Key observations:

  • The fix correctly resolves the type mismatch SonarCloud flagged; no functional regression is introduced.
  • However, remoteServerManager.removeServer(server.id) now returns an unguarded Promise. Internally it awaits removeApiKey, so a Keychain failure would result in an unhandled promise rejection and the store's removeServer would never be called (server wouldn't disappear from the list).
  • The rest of the file already uses .catch(() => {}) for fire-and-forget async calls (lines 44 and 88); the changed line should follow the same pattern for consistency and to prevent unhandled rejections.

Confidence Score: 4/5

  • This PR is safe to merge with a minor improvement suggested to add .catch() to the fire-and-forget call.
  • The change is minimal, targeted, and correct. The only concern is a missing .catch() on the now-unguarded Promise, which was also silently dropped before this fix but could lead to unhandled rejections and a UI inconsistency if removeApiKey fails. No new functional regression is introduced.
  • No files require special attention beyond the single-line .catch() suggestion in src/screens/RemoteServersScreen.tsx.

Important Files Changed

Filename Overview
src/screens/RemoteServersScreen.tsx Removes async/await from the delete server onPress callback to satisfy SonarCloud; removeServer is now fire-and-forget but its returned Promise is not guarded with .catch(), inconsistent with the pattern used elsewhere in the file.

Sequence Diagram

sequenceDiagram
    participant User
    participant RemoteServersScreen
    participant CustomAlert
    participant RemoteServerStore
    participant RemoteServerManager
    participant KeyChain

    User->>RemoteServersScreen: Tap "Delete"
    RemoteServersScreen->>CustomAlert: showAlert (confirm dialog)
    User->>CustomAlert: Tap "Delete" (confirm)
    CustomAlert->>RemoteServersScreen: onPress()
    RemoteServersScreen->>RemoteServerStore: setActiveServerId(null) [if active]
    RemoteServersScreen->>RemoteServerManager: removeServer(id) [fire-and-forget]
    Note over RemoteServersScreen,RemoteServerManager: Promise returned but not awaited
    RemoteServerManager->>RemoteServerManager: providerRegistry.unregisterProvider(id)
    RemoteServerManager->>KeyChain: removeApiKey(id)
    alt KeyChain success
        KeyChain-->>RemoteServerManager: resolved
        RemoteServerManager->>RemoteServerStore: removeServer(id)
    else KeyChain failure
        KeyChain-->>RemoteServerManager: rejected
        Note over RemoteServerManager: Unhandled rejection — store.removeServer never called
    end
Loading

Last reviewed commit: e927a74

Comment thread src/screens/RemoteServersScreen.tsx Outdated
onPress: () => {
if (activeServerId === server.id) setActiveServerId(null);
await remoteServerManager.removeServer(server.id);
remoteServerManager.removeServer(server.id);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unhandled promise rejection risk

remoteServerManager.removeServer is async and internally awaits removeApiKey. If removeApiKey rejects (e.g. Keychain error), the returned Promise will be silently dropped here, producing an unhandled promise rejection. The rest of the codebase already uses a consistent .catch(() => {}) pattern for fire-and-forget async calls (e.g. lines 44 and 88), so this should follow the same convention.

Suggested change
remoteServerManager.removeServer(server.id);
remoteServerManager.removeServer(server.id).catch(() => {});

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Addressed — went with Gemini's suggestion of showing an error alert rather than a silent .catch(() => {}) since this is a user-initiated action and they should know if deletion failed. Pushed in 489ebc8.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 14, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.44%. Comparing base (17dbf25) to head (489ebc8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/screens/RemoteServersScreen.tsx 50.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (50.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #174      +/-   ##
==========================================
- Coverage   86.46%   86.44%   -0.02%     
==========================================
  Files         214      214              
  Lines       10515    10516       +1     
  Branches     2818     2819       +1     
==========================================
- Hits         9092     9091       -1     
- Misses        772      773       +1     
- Partials      651      652       +1     
Files with missing lines Coverage Δ
src/screens/RemoteServersScreen.tsx 84.21% <50.00%> (-1.13%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Addresses Gemini and Greptile review comments — shows error alert
on deletion failure instead of silently swallowing the rejection.

Authored-by: GLM <work@wednesday.is>
@alichherawalla
Copy link
Copy Markdown
Owner Author

/gemini review

@sonarqubecloud
Copy link
Copy Markdown

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 correctly resolves the SonarCloud issue by removing the async keyword from the onPress callback, ensuring it returns void as expected. You've also improved robustness by adding error handling for the server deletion process, which now informs the user of failures via an alert. I have one suggestion to prevent a potential race condition that could cause a React warning if the component unmounts during the deletion.

Comment on lines +109 to +111
remoteServerManager.removeServer(server.id).catch(error =>
setAlertState(showAlert('Deletion Failed', error instanceof Error ? error.message : 'An unknown error occurred.'))
);
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

There's a potential race condition here. If the component unmounts after the delete operation starts but before it completes (e.g., the user navigates away quickly), setAlertState could be called on an unmounted component. This would result in a React warning about memory leaks.

To prevent this, you can use a useRef to track if the component is mounted.

First, add this to your component:

const isMounted = React.useRef(true);
React.useEffect(() => {
  return () => {
    isMounted.current = false;
  };
}, []);

Then, check this ref in your .catch block before calling setAlertState:

remoteServerManager.removeServer(server.id).catch(error => {
  if (isMounted.current) {
    setAlertState(showAlert('Deletion Failed', error instanceof Error ? error.message : 'An unknown error occurred.'));
  }
});

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.

1 participant