Sentry moved to lib. Catch markers errors
This commit is contained in:
parent
f476a099f8
commit
e6c3833765
4 changed files with 103 additions and 43 deletions
|
|
@ -21,6 +21,7 @@ import 'layerSelectorMapPlugin.dart';
|
||||||
import 'models/appState.dart';
|
import 'models/appState.dart';
|
||||||
import 'models/fireMapState.dart';
|
import 'models/fireMapState.dart';
|
||||||
import 'redux/actions.dart';
|
import 'redux/actions.dart';
|
||||||
|
import 'sentryReport.dart';
|
||||||
import 'slider.dart';
|
import 'slider.dart';
|
||||||
import 'zoomMapPlugin.dart';
|
import 'zoomMapPlugin.dart';
|
||||||
|
|
||||||
|
|
@ -37,6 +38,7 @@ class _ViewModel {
|
||||||
final OnLocationEditCancel onEditCancel;
|
final OnLocationEditCancel onEditCancel;
|
||||||
final OnLocationEditing onEditing;
|
final OnLocationEditing onEditing;
|
||||||
final OnFalsePositive onFalsePositive;
|
final OnFalsePositive onFalsePositive;
|
||||||
|
final OnFirePressedInMap onFirePressed;
|
||||||
|
|
||||||
_ViewModel(
|
_ViewModel(
|
||||||
{@required this.mapState,
|
{@required this.mapState,
|
||||||
|
|
@ -49,6 +51,7 @@ class _ViewModel {
|
||||||
@required this.onEditing,
|
@required this.onEditing,
|
||||||
@required this.onEditConfirm,
|
@required this.onEditConfirm,
|
||||||
@required this.onFalsePositive,
|
@required this.onFalsePositive,
|
||||||
|
@required this.onFirePressed,
|
||||||
@required this.onEditCancel});
|
@required this.onEditCancel});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -112,6 +115,9 @@ class _genericMapState extends State<genericMap> {
|
||||||
},
|
},
|
||||||
onFalsePositive: (notif, type) => store
|
onFalsePositive: (notif, type) => store
|
||||||
.dispatch(new MarkFireAsFalsePositiveAction(notif, type)),
|
.dispatch(new MarkFireAsFalsePositiveAction(notif, type)),
|
||||||
|
onFirePressed: (LatLng latLng, DateTime when) {
|
||||||
|
// _showFireDialog(latLng, when);
|
||||||
|
},
|
||||||
serverUrl: store.state.serverUrl,
|
serverUrl: store.state.serverUrl,
|
||||||
mapState: store.state.fireMapState);
|
mapState: store.state.fireMapState);
|
||||||
},
|
},
|
||||||
|
|
@ -225,11 +231,15 @@ class _genericMapState extends State<genericMap> {
|
||||||
: new DummyMapPluginOptions(),
|
: new DummyMapPluginOptions(),
|
||||||
new MarkerLayerOptions(
|
new MarkerLayerOptions(
|
||||||
markers: buildMarkers(
|
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.fires,
|
||||||
mapState.industries,
|
mapState.industries,
|
||||||
mapState.falsePos,
|
mapState.falsePos,
|
||||||
mapState.status == FireMapStatus.viewFireNotification),
|
mapState.status == FireMapStatus.viewFireNotification,
|
||||||
|
view.onFirePressed),
|
||||||
),
|
),
|
||||||
// new AttributionPluginOptions(text: "© OpenStreetMap contributors"),
|
// new AttributionPluginOptions(text: "© OpenStreetMap contributors"),
|
||||||
new LayerSelectorMapPluginOptions(),
|
new LayerSelectorMapPluginOptions(),
|
||||||
|
|
@ -380,34 +390,73 @@ class _genericMapState extends State<genericMap> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Marker> buildMarkers(LatLng pos, List<dynamic> fires,
|
List<Marker> buildMarkers(
|
||||||
List<dynamic> falsePosList, List<dynamic> industries, bool isNotif) {
|
LatLng pos,
|
||||||
|
List<dynamic> fires,
|
||||||
|
List<dynamic> falsePosList,
|
||||||
|
List<dynamic> industries,
|
||||||
|
bool isNotif,
|
||||||
|
OnFirePressedInMap onFirePressed) {
|
||||||
List<Marker> markers = [];
|
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
|
const calibrate = false; // useful when we change the fire icons size
|
||||||
falsePosList.forEach((falsePos) {
|
falsePosList.forEach((falsePos) {
|
||||||
var coords = falsePos['geo']['coordinates'];
|
try {
|
||||||
// print('false pos: ${coords}');
|
var coords = falsePos['geo']['coordinates'];
|
||||||
var loc = LatLng(coords[1], coords[0]);
|
// print('false pos: ${coords}');
|
||||||
markers.add(FireMarker(loc, FireMarkType.falsePos));
|
var loc = LatLng(coords[1], coords[0]);
|
||||||
if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel));
|
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) {
|
industries.forEach((industry) {
|
||||||
// print(fire['geo']['coordinates']);
|
try {
|
||||||
var coords = industry['geo']['coordinates'];
|
// print(fire['geo']['coordinates']);
|
||||||
var loc = LatLng(coords[1], coords[0]);
|
var coords = industry['geo']['coordinates'];
|
||||||
markers.add(FireMarker(loc, FireMarkType.industry));
|
var loc = LatLng(coords[1], coords[0]);
|
||||||
if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel));
|
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) {
|
fires.forEach((fire) {
|
||||||
var loc = new LatLng(fire['lat'], fire['lon']);
|
try {
|
||||||
markers.add(
|
var loc = new LatLng(fire['lat'], fire['lon']);
|
||||||
FireMarker(loc, FireMarkType.fire, () => print('marker pressed')));
|
markers.add(FireMarker(loc, FireMarkType.fire, () {
|
||||||
markers.add(FireMarker(loc, FireMarkType.pixel));
|
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(
|
markers.add(
|
||||||
pos, isNotif ? FireMarkType.fire : FireMarkType.position));
|
FireMarker(pos, isNotif ? FireMarkType.fire : FireMarkType.position));
|
||||||
if (calibrate) markers.add(FireMarker(pos, FireMarkType.pixel));
|
if (calibrate) markers.add(FireMarker(pos, FireMarkType.pixel));
|
||||||
return markers;
|
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);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import 'models/firesApi.dart';
|
||||||
import 'redux/fetchDataMiddleware.dart';
|
import 'redux/fetchDataMiddleware.dart';
|
||||||
import 'redux/reducers.dart';
|
import 'redux/reducers.dart';
|
||||||
import 'package:package_info/package_info.dart';
|
import 'package:package_info/package_info.dart';
|
||||||
|
import 'sentryReport.dart';
|
||||||
|
|
||||||
Future<PackageInfo> loadPackageInfo() async {
|
Future<PackageInfo> loadPackageInfo() async {
|
||||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
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.serverUrl, key: "serverUrl");
|
||||||
injector.map<String>((i) => store.state.gmapKey, key: "gmapKey");
|
injector.map<String>((i) => store.state.gmapKey, key: "gmapKey");
|
||||||
|
|
||||||
var useSentry = !globals.isDevelopment;
|
if (useSentry) {
|
||||||
|
SentryClient _sentry = SentryClient(dsn: secrets['sentryDSN']);
|
||||||
SentryClient _sentry;
|
injector.map<SentryClient>((i) => _sentry);
|
||||||
if (useSentry) _sentry = SentryClient(dsn: secrets['sentryDSN']);
|
}
|
||||||
|
|
||||||
// https://flutter.io/cookbook/maintenance/error-reporting/
|
// https://flutter.io/cookbook/maintenance/error-reporting/
|
||||||
runZoned<Future<Null>>(() async {
|
runZoned<Future<Null>>(() async {
|
||||||
|
|
@ -56,7 +57,7 @@ void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
||||||
}, onError: (error, stackTrace) {
|
}, onError: (error, stackTrace) {
|
||||||
// Whenever an error occurs, call the `_reportError` function. This will send
|
// Whenever an error occurs, call the `_reportError` function. This will send
|
||||||
// Dart errors to our dev console or Sentry depending on the environment.
|
// 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
|
// 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,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import 'user.dart';
|
||||||
|
|
||||||
export 'fireMapState.dart';
|
export 'fireMapState.dart';
|
||||||
import 'package:flutter_map/flutter_map.dart';
|
import 'package:flutter_map/flutter_map.dart';
|
||||||
|
import 'package:latlong/latlong.dart';
|
||||||
|
|
||||||
part 'appState.g.dart';
|
part 'appState.g.dart';
|
||||||
|
|
||||||
|
|
@ -123,6 +124,7 @@ typedef void OnLocationEditing(YourLocation loc);
|
||||||
typedef void OnLocationEditConfirm(YourLocation loc);
|
typedef void OnLocationEditConfirm(YourLocation loc);
|
||||||
typedef void OnLocationEditCancel(YourLocation loc);
|
typedef void OnLocationEditCancel(YourLocation loc);
|
||||||
typedef void TapFireNotificationFunction(FireNotification notif);
|
typedef void TapFireNotificationFunction(FireNotification notif);
|
||||||
|
typedef void OnFirePressedInMap(LatLng latLng, DateTime when);
|
||||||
// typedef void OnReceivedFireNotificationFunction(FireNotification notif);
|
// typedef void OnReceivedFireNotificationFunction(FireNotification notif);
|
||||||
typedef void DeleteFireNotificationFunction(FireNotification notif);
|
typedef void DeleteFireNotificationFunction(FireNotification notif);
|
||||||
typedef void DeleteAllFireNotificationFunction();
|
typedef void DeleteAllFireNotificationFunction();
|
||||||
|
|
|
||||||
25
lib/sentryReport.dart
Normal file
25
lib/sentryReport.dart
Normal 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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue