From 55e8427e3ddfb1f639f01ba1f7f35ac269754ec4 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Fri, 26 Jan 2024 18:58:47 +0100 Subject: [PATCH] reporting: privent noisy reports --- lib/image_providers/thumbnail_provider.dart | 5 +++-- lib/image_providers/uri_image_provider.dart | 5 +++-- lib/services/geocoding_service.dart | 11 ++--------- plugins/aves_report/lib/aves_report.dart | 4 ++++ .../lib/aves_report_platform.dart | 4 +++- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/image_providers/thumbnail_provider.dart b/lib/image_providers/thumbnail_provider.dart index 33f05fec4..c9f868296 100644 --- a/lib/image_providers/thumbnail_provider.dart +++ b/lib/image_providers/thumbnail_provider.dart @@ -1,6 +1,7 @@ import 'dart:ui' as ui; import 'package:aves/services/common/services.dart'; +import 'package:aves_report/aves_report.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; @@ -46,14 +47,14 @@ class ThumbnailProvider extends ImageProvider { taskKey: key, ); if (bytes.isEmpty) { - throw StateError('$uri ($mimeType) loading failed'); + throw UnreportedStateError('$uri ($mimeType) loading failed'); } final buffer = await ui.ImmutableBuffer.fromUint8List(bytes); return await decode(buffer); } catch (error) { // loading may fail if the provided MIME type is incorrect (e.g. the Media Store may report a JPEG as a TIFF) debugPrint('$runtimeType _loadAsync failed with mimeType=$mimeType, uri=$uri, error=$error'); - throw StateError('$mimeType decoding failed (page $pageId)'); + throw UnreportedStateError('$mimeType decoding failed (page $pageId)'); } } diff --git a/lib/image_providers/uri_image_provider.dart b/lib/image_providers/uri_image_provider.dart index 38842e742..4d3b46713 100644 --- a/lib/image_providers/uri_image_provider.dart +++ b/lib/image_providers/uri_image_provider.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:ui' as ui; import 'package:aves/services/common/services.dart'; +import 'package:aves_report/aves_report.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; @@ -64,14 +65,14 @@ class UriImage extends ImageProvider with EquatableMixin { }, ); if (bytes.isEmpty) { - throw StateError('$uri ($mimeType) loading failed'); + throw UnreportedStateError('$uri ($mimeType) loading failed'); } final buffer = await ui.ImmutableBuffer.fromUint8List(bytes); return await decode(buffer); } catch (error) { // loading may fail if the provided MIME type is incorrect (e.g. the Media Store may report a JPEG as a TIFF) debugPrint('$runtimeType _loadAsync failed with mimeType=$mimeType, uri=$uri, error=$error'); - throw StateError('$mimeType decoding failed (page $pageId)'); + throw UnreportedStateError('$mimeType decoding failed (page $pageId)'); } finally { unawaited(chunkEvents.close()); } diff --git a/lib/services/geocoding_service.dart b/lib/services/geocoding_service.dart index 15af95974..c84390d93 100644 --- a/lib/services/geocoding_service.dart +++ b/lib/services/geocoding_service.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:ui'; -import 'package:aves/services/common/services.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; @@ -22,14 +21,8 @@ class GeocodingService { 'maxResults': 2, }); return (result as List).cast().map(Address.fromMap).toList(); - } on PlatformException catch (e, stack) { - if (!{ - 'getAddress-empty', - 'getAddress-network', - 'getAddress-unavailable', - }.contains(e.code)) { - await reportService.recordError(e, stack); - } + } on PlatformException catch (_) { + // do not report } return []; } diff --git a/plugins/aves_report/lib/aves_report.dart b/plugins/aves_report/lib/aves_report.dart index 4675cf2b0..765e5efc0 100644 --- a/plugins/aves_report/lib/aves_report.dart +++ b/plugins/aves_report/lib/aves_report.dart @@ -35,3 +35,7 @@ abstract class ReportService { .join('\n')); } } + +class UnreportedStateError extends StateError { + UnreportedStateError(super.message); +} \ No newline at end of file diff --git a/plugins/aves_report_crashlytics/lib/aves_report_platform.dart b/plugins/aves_report_crashlytics/lib/aves_report_platform.dart index 67fd00aec..876644568 100644 --- a/plugins/aves_report_crashlytics/lib/aves_report_platform.dart +++ b/plugins/aves_report_crashlytics/lib/aves_report_platform.dart @@ -71,7 +71,9 @@ class PlatformReportService extends ReportService { if (exception is PlatformException && stack != null) { stack = ReportService.buildReportStack(stack, level: 2); } - return _instance?.recordError(exception, stack); + if (exception! is UnreportedStateError) { + return _instance?.recordError(exception, stack); + } } @override