Skip to content

Commit

Permalink
Don't log errors if error occurs before files are init
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Lesches committed Oct 15, 2024
1 parent 5943588 commit a41ce34
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/src/services/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class FilesService extends Service {
/// The encoder to convert a Map<> to a json string with a nice indent
final JsonEncoder jsonEncoder = const JsonEncoder.withIndent(" ");

bool _isInit = false;

/// Ensure that files and directories that are expected to be present actually
/// exist on the system. If not, create them.
@override
Expand All @@ -58,6 +60,7 @@ class FilesService extends Service {
loggingDir = await Directory("${outputDir.path}/logs/${DateTime.now().timeStamp}").create(recursive: true);
if (!settingsFile.existsSync()) await writeSettings(null);
dataLogger = Timer.periodic(const Duration(seconds: 5), logAllData);
_isInit = true;
}

@override
Expand Down Expand Up @@ -139,6 +142,7 @@ class FilesService extends Service {

/// Outputs error to log file
Future<void> logError(Object error, StackTrace stack) async{
if (!_isInit) return;
final file = loggingDir / "errors.log";
await file.writeAsString("${DateTime.now().timeStamp} $error $stack\n", mode: FileMode.writeOnlyAppend);
}
Expand Down

0 comments on commit a41ce34

Please sign in to comment.