Skip to content

Commit

Permalink
error logging (#109)
Browse files Browse the repository at this point in the history
hope this works

---------

Co-authored-by: Levi Lesches <[email protected]>
  • Loading branch information
aidanahram and Levi-Lesches authored Jun 1, 2023
1 parent 281c1ed commit 6247b4a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/src/services/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> 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 {
Expand Down
6 changes: 3 additions & 3 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 6247b4a

Please sign in to comment.