Skip to content

Commit

Permalink
reporting: privent noisy reports
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerst committed Jan 26, 2024
1 parent 2e13879 commit 55e8427
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions lib/image_providers/thumbnail_provider.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -46,14 +47,14 @@ class ThumbnailProvider extends ImageProvider<ThumbnailProviderKey> {
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)');
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/image_providers/uri_image_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -64,14 +65,14 @@ class UriImage extends ImageProvider<UriImage> 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());
}
Expand Down
11 changes: 2 additions & 9 deletions lib/services/geocoding_service.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -22,14 +21,8 @@ class GeocodingService {
'maxResults': 2,
});
return (result as List).cast<Map>().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 [];
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/aves_report/lib/aves_report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ abstract class ReportService {
.join('\n'));
}
}

class UnreportedStateError extends StateError {
UnreportedStateError(super.message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55e8427

Please sign in to comment.