Skip to content

fix: replace unhandled throw with logger.e in FAQ screen launchUrl#3385

Merged
marcnause merged 1 commit into
fossasia:mainfrom
prajakta128:fix/faq-launchurl-throw-crash
Jul 1, 2026
Merged

fix: replace unhandled throw with logger.e in FAQ screen launchUrl#3385
marcnause merged 1 commit into
fossasia:mainfrom
prajakta128:fix/faq-launchurl-throw-crash

Conversation

@prajakta128

@prajakta128 prajakta128 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #3384

Problem

_launchURL() in lib/view/faq_screen.dart throws a raw string exception when canLaunchUrl returns false. The only call site is a fire-and-forget onTap handler with no try/catch, so the exception is never caught and crashes the app.

Root Cause

Future<void> _launchURL(String url) async {
  final Uri uri = Uri.parse(url);
  if (await canLaunchUrl(uri)) {
    await launchUrl(uri);
  } else {
    throw '${appLocalizations.launchError} $url';
  }
}

The call site:

onTap: () => _launchURL(faq.linkUrl!),

Fix

Replaced the throw with logger.e(), matching the pattern already used in about_us_screen.dart for the same kind of failure:

Future<void> _launchURL(String url) async {
  final Uri uri = Uri.parse(url);
  if (await canLaunchUrl(uri)) {
    await launchUrl(uri);
  } else {
    logger.e('${appLocalizations.launchError} $url');
  }
}

Impact

  • Prevents app crash when a FAQ link cannot be launched
  • Consistent with existing logger usage elsewhere in the app
  • No UI change

Screenshots / Recordings

N/A — crash fix, no UI changes

Checklist

  • No hard coding: I have used values from constants.dart or localization files instead of hard-coded values.
  • No end of file edits: No modifications done at end of resource files.
  • Code reformatting: I have formatted the code using dart format or the IDE formatter.
  • Code analysis: My code passes checks run in flutter analyze and tests run in flutter test.

Summary by Sourcery

Bug Fixes:

  • Prevent app crashes when failing to launch FAQ links by logging errors instead of throwing uncaught exceptions.

@sourcery-ai

sourcery-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces an unhandled thrown string in the FAQ screen URL launcher with structured logging, preventing crashes when URL launch fails and aligning with existing logger usage patterns.

Sequence diagram for updated FAQ URL launch behavior

sequenceDiagram
    actor User
    participant FAQScreen
    participant _launchURL
    participant canLaunchUrl
    participant launchUrl
    participant logger

    User ->> FAQScreen: onTap
    FAQScreen ->> _launchURL: _launchURL(faq.linkUrl)
    _launchURL ->> canLaunchUrl: canLaunchUrl(uri)
    canLaunchUrl -->> _launchURL: bool

    alt [canLaunchUrl returns true]
        _launchURL ->> launchUrl: launchUrl(uri)
    else [canLaunchUrl returns false]
        _launchURL ->> logger: e(appLocalizations.launchError + url)
    end
Loading

File-Level Changes

Change Details Files
Handle FAQ link launch failures via logger instead of throwing, and wire in the logger dependency.
  • Imported the shared logger service into the FAQ screen
  • Replaced the thrown string exception in _launchURL with a logger.e call using the localized launch error message and URL
lib/view/faq_screen.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#3384 Prevent the FAQ screen from crashing when a link URL cannot be launched by handling launch failures gracefully (logging the error instead of throwing), consistent with about_us_screen.dart.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've left some high level feedback:

  • Consider providing some lightweight user feedback (e.g., a SnackBar or dialog) when canLaunchUrl returns false so failures aren’t completely silent and users know the tap didn’t succeed.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider providing some lightweight user feedback (e.g., a SnackBar or dialog) when `canLaunchUrl` returns false so failures aren’t completely silent and users know the tap didn’t succeed.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

_launchURL() in faq_screen.dart threw a raw string when canLaunchUrl
returned false. This throw was never caught at the call site
(onTap: () => _launchURL(faq.linkUrl!)), so it propagated up and
crashed the app instead of failing gracefully.

Replaced the throw with logger.e(), consistent with how launchUrl
failures are already handled in about_us_screen.dart.

Fixes fossasia#3384
@marcnause marcnause force-pushed the fix/faq-launchurl-throw-crash branch from 9b25546 to cd1750f Compare July 1, 2026 20:09
@marcnause marcnause enabled auto-merge (rebase) July 1, 2026 20:12
@marcnause marcnause merged commit 2f3b19b into fossasia:main Jul 1, 2026
14 of 15 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.

bug: FAQ screen crashes app when link URL cannot be launched

3 participants