fix(dive-computer): log download failures to the file log#258
Merged
Conversation
The DownloadNotifier handled DownloadErrorEvent and caught startDownload exceptions by updating UI state only, never calling the logger. Users reporting "Download failed" had no [LDC] or [ERROR] entries in their log file, making remote diagnosis impossible. Now both error paths emit _log.error(...) under LogCategory.libdc with the error code, message, and (for the Dart catch) stack trace. Tested via two new cases in download_notifier_fingerprint_test.dart that subscribe to LoggerService.logStream and assert exactly one ERROR entry per failure path.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves diagnosability of dive-computer download failures by ensuring DownloadNotifier emits LogLevel.error entries under LogCategory.libdc for both plugin error events and Dart-side startDownload exceptions, and adds tests to verify those logs are produced.
Changes:
- Add libdc error logging when
startDownloadthrows (including exception + stack trace). - Add libdc error logging when a
DownloadErrorEventis received (including error code/message). - Add tests that subscribe to
LoggerService.logStreamand assert exactly one error log entry per failure path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/features/dive_computer/presentation/providers/download_providers.dart | Add _log.error(...) calls for startDownload exceptions and DownloadErrorEvent handling. |
| test/features/dive_computer/presentation/providers/download_notifier_fingerprint_test.dart | Add tests validating error logs are emitted for both failure paths. |
Comments suppressed due to low confidence (1)
lib/features/dive_computer/presentation/providers/download_providers.dart:177
- In the
startDownloadexception path, the download events subscription has already been created (_service.downloadEvents.listen(...)) but is not cancelled whenstartDownloadthrows. This can leave a dangling listener that may continue to receive events and mutate state after an immediate start failure. Cancel and null out_downloadSubscriptionin the catch block (and consider also calling_service.cancelDownload()if appropriate) to keep state consistent and avoid leaks.
} catch (e, stackTrace) {
_log.error(
'Download failed',
category: LogCategory.libdc,
error: e,
stackTrace: stackTrace,
);
state = state.copyWith(
phase: DownloadPhase.error,
errorMessage: 'Download failed: $e',
);
}
Address PR review on #258: - If _service.startDownload throws synchronously, the catch block now cancels _downloadSubscription so stray native events cannot mutate state (or double-log) after a start failure. - Test cleanup moved to addTearDown so a failing expectation can no longer leak the LoggerService.logStream subscription into later tests. - New tests filter the log stream by both LogLevel.error AND LogCategory.libdc to avoid false positives from unrelated error logs. - Added a regression test that pushes a stray DownloadErrorEvent after a synchronous start failure and asserts only the catch-block log entry is captured.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DownloadNotifierhandledDownloadErrorEventand caughtstartDownloadexceptions by updating UI state only, never calling the logger. A user reporting "Download failed" on a Shearwater Teric over Windows 11 BLE had no[LDC]or[ERROR]entries insubmersion.log, making remote diagnosis impossible._log.error(...)underLogCategory.libdc. The Dart catch block also forwards the exception and stack trace; the nativeDownloadErrorEventhandler logs the error code and message from libdivecomputer.Why
Without a logged error, a libdc-reported BLE comms failure, a permission error on
startDownload, and a "download completed with 0 dives" outcome are all indistinguishable in a user-submitted log. This blocks support triage on exactly the flows most likely to break (BLE dive computers on Windows).Test plan
flutter test test/features/dive_computer/presentation/providers/download_notifier_fingerprint_test.dart— 5/5 pass (2 new)LoggerService.logStream, assert exactly oneLogLevel.errorentry per failure path with the expected category and message substringshasLength(1)vs[]), then GREEN after the fixdart format— cleanflutter analyze— "No issues found"