Sentry moved to lib. Catch markers errors

This commit is contained in:
Vicente J. Ruiz Jurado 2018-08-17 12:04:58 +02:00
parent f476a099f8
commit e6c3833765
4 changed files with 103 additions and 43 deletions

View file

@ -21,6 +21,7 @@ import 'layerSelectorMapPlugin.dart';
import 'models/appState.dart';
import 'models/fireMapState.dart';
import 'redux/actions.dart';
import 'sentryReport.dart';
import 'slider.dart';
import 'zoomMapPlugin.dart';
@ -37,6 +38,7 @@ class _ViewModel {
final OnLocationEditCancel onEditCancel;
final OnLocationEditing onEditing;
final OnFalsePositive onFalsePositive;
final OnFirePressedInMap onFirePressed;
_ViewModel(
{@required this.mapState,
@ -49,6 +51,7 @@ class _ViewModel {
@required this.onEditing,
@required this.onEditConfirm,
@required this.onFalsePositive,
@required this.onFirePressed,
@required this.onEditCancel});
@override
@ -112,6 +115,9 @@ class _genericMapState extends State<genericMap> {
},
onFalsePositive: (notif, type) => store
.dispatch(new MarkFireAsFalsePositiveAction(notif, type)),
onFirePressed: (LatLng latLng, DateTime when) {
// _showFireDialog(latLng, when);
},
serverUrl: store.state.serverUrl,
mapState: store.state.fireMapState);
},
@ -225,11 +231,15 @@ class _genericMapState extends State<genericMap> {
: new DummyMapPluginOptions(),
new MarkerLayerOptions(
markers: buildMarkers(
mapState.status == FireMapStatus.viewFireNotification ? new LatLng(mapState.fireNotification.lat, mapState.fireNotification.lon): new LatLng(_location.lat, _location.lon),
mapState.status == FireMapStatus.viewFireNotification
? new LatLng(mapState.fireNotification.lat,
mapState.fireNotification.lon)
: new LatLng(_location.lat, _location.lon),
mapState.fires,
mapState.industries,
mapState.falsePos,
mapState.status == FireMapStatus.viewFireNotification),
mapState.status == FireMapStatus.viewFireNotification,
view.onFirePressed),
),
// new AttributionPluginOptions(text: "© OpenStreetMap contributors"),
new LayerSelectorMapPluginOptions(),
@ -380,34 +390,73 @@ class _genericMapState extends State<genericMap> {
}
}
List<Marker> buildMarkers(LatLng pos, List<dynamic> fires,
List<dynamic> falsePosList, List<dynamic> industries, bool isNotif) {
List<Marker> buildMarkers(
LatLng pos,
List<dynamic> fires,
List<dynamic> falsePosList,
List<dynamic> industries,
bool isNotif,
OnFirePressedInMap onFirePressed) {
List<Marker> markers = [];
print('building markers: fires: ${fires.length} falsePos: ${falsePosList.length} industries: ${industries.length}, isNotif: ${isNotif} ');
print('building markers: fires: ${fires.length} falsePos: ${falsePosList
.length} industries: ${industries.length}, isNotif: ${isNotif} ');
const calibrate = false; // useful when we change the fire icons size
falsePosList.forEach((falsePos) {
var coords = falsePos['geo']['coordinates'];
// print('false pos: ${coords}');
var loc = LatLng(coords[1], coords[0]);
markers.add(FireMarker(loc, FireMarkType.falsePos));
if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel));
try {
var coords = falsePos['geo']['coordinates'];
// print('false pos: ${coords}');
var loc = LatLng(coords[1], coords[0]);
markers.add(FireMarker(loc, FireMarkType.falsePos));
if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel));
} catch (e) {
print('Failed to process $falsePos');
reportError(e, e.stackTrace);
}
});
industries.forEach((industry) {
// print(fire['geo']['coordinates']);
var coords = industry['geo']['coordinates'];
var loc = LatLng(coords[1], coords[0]);
markers.add(FireMarker(loc, FireMarkType.industry));
if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel));
try {
// print(fire['geo']['coordinates']);
var coords = industry['geo']['coordinates'];
var loc = LatLng(coords[1], coords[0]);
markers.add(FireMarker(loc, FireMarkType.industry));
if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel));
} catch (e) {
print('Failed to process $industry');
reportError(e, e.stackTrace);
}
});
fires.forEach((fire) {
var loc = new LatLng(fire['lat'], fire['lon']);
markers.add(
FireMarker(loc, FireMarkType.fire, () => print('marker pressed')));
markers.add(FireMarker(loc, FireMarkType.pixel));
try {
var loc = new LatLng(fire['lat'], fire['lon']);
markers.add(FireMarker(loc, FireMarkType.fire, () {
onFirePressed(loc, DateTime.parse(fire['when']));
print('fire $fire pressed');
}));
markers.add(FireMarker(loc, FireMarkType.pixel));
} catch (e) {
print('Failed to process $fire');
reportError(e, e.stackTrace);
}
});
markers.add(FireMarker(
pos, isNotif ? FireMarkType.fire : FireMarkType.position));
markers.add(
FireMarker(pos, isNotif ? FireMarkType.fire : FireMarkType.position));
if (calibrate) markers.add(FireMarker(pos, FireMarkType.pixel));
return markers;
}
void _showFireDialog(LatLng latLng, DateTime when) {
showDialog<bool>(
context: _scaffoldKey.currentContext,
builder: (_) => new AlertDialog(
content: new Text('FIXME'),
actions: <Widget>[
new FlatButton(
child: Text(S.of(_scaffoldKey.currentContext).CLOSE),
onPressed: () {
Navigator.pop(_scaffoldKey.currentContext);
},
),
],
));
}
}

View file

@ -13,6 +13,7 @@ import 'models/firesApi.dart';
import 'redux/fetchDataMiddleware.dart';
import 'redux/reducers.dart';
import 'package:package_info/package_info.dart';
import 'sentryReport.dart';
Future<PackageInfo> loadPackageInfo() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
@ -45,10 +46,10 @@ void mainCommon(List<Middleware<AppState>> otherMiddleware) {
injector.map<String>((i) => store.state.serverUrl, key: "serverUrl");
injector.map<String>((i) => store.state.gmapKey, key: "gmapKey");
var useSentry = !globals.isDevelopment;
SentryClient _sentry;
if (useSentry) _sentry = SentryClient(dsn: secrets['sentryDSN']);
if (useSentry) {
SentryClient _sentry = SentryClient(dsn: secrets['sentryDSN']);
injector.map<SentryClient>((i) => _sentry);
}
// https://flutter.io/cookbook/maintenance/error-reporting/
runZoned<Future<Null>>(() async {
@ -56,7 +57,7 @@ void mainCommon(List<Middleware<AppState>> otherMiddleware) {
}, onError: (error, stackTrace) {
// Whenever an error occurs, call the `_reportError` function. This will send
// Dart errors to our dev console or Sentry depending on the environment.
_reportError(useSentry, _sentry, error, stackTrace);
reportError(error, stackTrace);
});
// Listen to store changes, and re-render when the state is updated
@ -76,20 +77,3 @@ void mainCommon(List<Middleware<AppState>> otherMiddleware) {
});
});
}
Future<Null> _reportError(bool useSentry, SentryClient sentry, dynamic error,
dynamic stackTrace) async {
// Print the exception to the console
print('Caught error: $error');
if (!useSentry) {
// Print the full stacktrace in debug mode
print(stackTrace);
return;
} else {
// Send the Exception and Stacktrace to Sentry in Production mode
sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
}
}

View file

@ -13,6 +13,7 @@ import 'user.dart';
export 'fireMapState.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
part 'appState.g.dart';
@ -123,6 +124,7 @@ typedef void OnLocationEditing(YourLocation loc);
typedef void OnLocationEditConfirm(YourLocation loc);
typedef void OnLocationEditCancel(YourLocation loc);
typedef void TapFireNotificationFunction(FireNotification notif);
typedef void OnFirePressedInMap(LatLng latLng, DateTime when);
// typedef void OnReceivedFireNotificationFunction(FireNotification notif);
typedef void DeleteFireNotificationFunction(FireNotification notif);
typedef void DeleteAllFireNotificationFunction();

25
lib/sentryReport.dart Normal file
View file

@ -0,0 +1,25 @@
import 'dart:async';
import 'package:flutter_simple_dependency_injection/injector.dart';
import 'package:sentry/sentry.dart';
import 'globals.dart' as globals;
var useSentry = !globals.isDevelopment;
Future<Null> reportError(dynamic error, dynamic stackTrace) async {
// Print the exception to the console
print('Caught error: $error');
if (!useSentry) {
// Print the full stacktrace in debug mode
print(stackTrace);
return;
} else {
// Send the Exception and Stacktrace to Sentry in Production mode
Injector.getInjector().get<SentryClient>().captureException(
exception: error,
stackTrace: stackTrace,
);
}
}