From 87866d520f94c4121bac77f776da8b36fd01cc6a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 10:22:26 +0000 Subject: [PATCH] fix(editor): catch the errors when opening a link of a note launchUrl was neither awaited nor caught, so a link that could not be opened (no app for its scheme, platform error) threw an unhandled error. The failure is now logged, without the exception which can contain the URL. Refs #609 Co-Authored-By: Claude --- lib/common/system_utils.dart | 13 +++++++++++-- .../editor/widgets/editors/markdown_editor.dart | 4 +++- .../editor/widgets/editors/rich_text_editor.dart | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/common/system_utils.dart b/lib/common/system_utils.dart index a5409528..d38afa66 100644 --- a/lib/common/system_utils.dart +++ b/lib/common/system_utils.dart @@ -237,7 +237,9 @@ class SystemUtils { } /// Opens the [url] of a link in a note, if it can be parsed. - void openLink(String? url) { + /// + /// The failures are logged, without the [url] which can contain private information. + Future openLink(String? url) async { if (url == null) { return; } @@ -249,6 +251,13 @@ class SystemUtils { return; } - launchUrl(uri); + try { + if (!await launchUrl(uri)) { + logger.w('The link in a note could not be opened'); + } + } catch (exception, stackTrace) { + // The exception itself is not logged, since it can contain the URL + logger.e('The link in a note could not be opened (${exception.runtimeType})', null, stackTrace); + } } } diff --git a/lib/pages/editor/widgets/editors/markdown_editor.dart b/lib/pages/editor/widgets/editors/markdown_editor.dart index b0b297d9..bc6cd13b 100644 --- a/lib/pages/editor/widgets/editors/markdown_editor.dart +++ b/lib/pages/editor/widgets/editors/markdown_editor.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; @@ -60,7 +62,7 @@ class _MarkdownEditorState extends ConsumerState { widget.onChanged(note); } - void onOpenLink(String text, String? href, String title) => SystemUtils().openLink(href); + void onOpenLink(String text, String? href, String title) => unawaited(SystemUtils().openLink(href)); @override Widget build(BuildContext context) { diff --git a/lib/pages/editor/widgets/editors/rich_text_editor.dart b/lib/pages/editor/widgets/editors/rich_text_editor.dart index d61f32f4..057e4242 100644 --- a/lib/pages/editor/widgets/editors/rich_text_editor.dart +++ b/lib/pages/editor/widgets/editors/rich_text_editor.dart @@ -60,7 +60,7 @@ class _RichTextEditorState extends ConsumerState { changes = widget.fleatherController.document.changes.listen((_) => onChanged()); } - void onLaunchUrl(String? url) => SystemUtils().openLink(url); + void onLaunchUrl(String? url) => unawaited(SystemUtils().openLink(url)); /// Updates whether the undo and redo actions are available. void updateUndoRedo() {