From 6247b4af59afe335c2707c2bed9280e106760334 Mon Sep 17 00:00:00 2001 From: aidanahram <52716460+aidanahram@users.noreply.github.com> Date: Thu, 1 Jun 2023 00:46:55 -0400 Subject: [PATCH] error logging (#109) hope this works --------- Co-authored-by: Levi Lesches --- lib/main.dart | 8 +++++++- lib/src/services/files.dart | 6 ++++++ macos/Podfile.lock | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index d5748877d..a14827340 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,14 +15,20 @@ import "package:flutter/material.dart"; import "package:rover_dashboard/app.dart"; import "package:rover_dashboard/data.dart"; import "package:rover_dashboard/models.dart"; +import "package:rover_dashboard/services.dart"; + +/// Network errors that can be fixed by a simple reset. +const networkErrors = {1234, 1231}; void main() async { runZonedGuarded( () => runApp(RoverControlDashboard()), (error, stack) async { - if (error is SocketException && error.osError!.errorCode == 1234) { + if (error is SocketException && networkErrors.contains(error.osError!.errorCode)) { models.home.setMessage(severity: Severity.critical, text: "Network error, restart by clicking the network icon"); } else { + models.home.setMessage(severity: Severity.critical, text: "Error occurred in the dashboard. See the logs"); + services.files.logError(error, stack); Error.throwWithStackTrace(error, stack); } } diff --git a/lib/src/services/files.dart b/lib/src/services/files.dart index 07d5a4fbe..1f597aae7 100644 --- a/lib/src/services/files.dart +++ b/lib/src/services/files.dart @@ -124,6 +124,12 @@ class FilesService extends Service { for (final line in (await file.readAsString()).trim().split("\n")) WrappedMessage.fromBuffer(base64.decode(line)) ]; + + /// Outputs error to log file + Future logError(Object error, StackTrace stack) async{ + final file = File("${loggingDir.path}/errors.txt"); + await file.writeAsString("${DateTime.now().timeStamp} $error $stack\n", mode: FileMode.writeOnlyAppend); + } } extension on FileSystemEntity { diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 152e103e6..584ecc52c 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -16,7 +16,7 @@ DEPENDENCIES: - flutter_libserialport (from `Flutter/ephemeral/.symlinks/plugins/flutter_libserialport/macos`) - FlutterMacOS (from `Flutter/ephemeral`) - package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`) - - path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos`) + - path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`) - url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`) SPEC REPOS: @@ -31,7 +31,7 @@ EXTERNAL SOURCES: package_info_plus: :path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos path_provider_foundation: - :path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos + :path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin url_launcher_macos: :path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos @@ -40,7 +40,7 @@ SPEC CHECKSUMS: FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 libserialport: 1cb25e66ef3c92a8e59c2ea3820302c3fa2268cd package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce - path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9 + path_provider_foundation: eaf5b3e458fc0e5fbb9940fb09980e853fe058b8 url_launcher_macos: 5335912b679c073563f29d89d33d10d459f95451 PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7