-
Notifications
You must be signed in to change notification settings - Fork 1
feat: New capabilities #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ import "package:flutter/material.dart" show BuildContext; | |||||||||||||||||||
|
|
||||||||||||||||||||
| abstract class EventResolver { | ||||||||||||||||||||
| final UIDriver driver; | ||||||||||||||||||||
| @Deprecated("Use [LoggingCapabilityDelegate] instead") | ||||||||||||||||||||
| final DebugLogger? logger; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| EventResolver({ | ||||||||||||||||||||
|
|
@@ -32,8 +33,6 @@ final class DefaultEventResolver extends EventResolver { | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| try { | ||||||||||||||||||||
| final driver = this.driver; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| switch (event) { | ||||||||||||||||||||
| case UpdateEvent(): | ||||||||||||||||||||
| event.updates.forEach((key, value) async { | ||||||||||||||||||||
|
|
@@ -46,7 +45,7 @@ final class DefaultEventResolver extends EventResolver { | |||||||||||||||||||
| "ExternalEventHandler instance is not set", | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| if (driver.externalEventHandler != null) { | ||||||||||||||||||||
| logger?.error("ExternalEventHandler instance is not set"); | ||||||||||||||||||||
| driver.logError("ExternalEventHandler instance is not set"); | ||||||||||||||||||||
| throw StateError("ExternalEventHandler instance is not set"); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| await driver.externalEventHandler?.handleNavigation( | ||||||||||||||||||||
|
|
@@ -57,7 +56,7 @@ final class DefaultEventResolver extends EventResolver { | |||||||||||||||||||
| break; | ||||||||||||||||||||
| case OpenUrlEvent(): | ||||||||||||||||||||
| if (driver.externalEventHandler != null) { | ||||||||||||||||||||
| logger?.error("ExternalEventHandler instance is not set"); | ||||||||||||||||||||
| driver.logError("ExternalEventHandler instance is not set"); | ||||||||||||||||||||
| throw StateError("ExternalEventHandler instance is not set"); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
58
to
61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical logic error: Inverted null check (duplicate issue). Same inverted logic as in the NavigationEvent case. The condition should check if the handler IS null before logging and throwing an error. 🐛 Proposed fix- if (driver.externalEventHandler != null) {
+ if (driver.externalEventHandler == null) {
driver.logError("ExternalEventHandler instance is not set");
throw StateError("ExternalEventHandler instance is not set");
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| await driver.externalEventHandler?.handleOpenUrl(event.url); | ||||||||||||||||||||
|
|
@@ -106,10 +105,10 @@ final class DefaultEventResolver extends EventResolver { | |||||||||||||||||||
| break; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } catch (e, s) { | ||||||||||||||||||||
| logger?.error( | ||||||||||||||||||||
| driver.logError( | ||||||||||||||||||||
| "Error while resolving ${event.type} event", | ||||||||||||||||||||
| error: e, | ||||||||||||||||||||
| stackTrace: s, | ||||||||||||||||||||
| e, | ||||||||||||||||||||
| s, | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export "logging_capability.dart"; | ||
| export "io.dart" if (dart.library.js_interop) "web.dart"; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import "package:duit_kernel/src/capabilities/logging/logging_capability.dart"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import "package:flutter/foundation.dart"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// A class that provides logging capabilities for the Duit UI system. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// This class implements the [LoggingCapabilityDelegate] mixin and provides | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// concrete implementations for logging messages at different levels. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final class LoggingManager with LoggingCapabilityDelegate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const LoggingManager(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void logCritical(message, [Object? exception, StackTrace? stackTrace]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final buff = StringBuffer("[DUIT FRAMEWORK] CRITICAL: $message \nTime: ${DateTime.now().toUtc()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lesleysin marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (exception != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nException: ${exception.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stackTrace != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| debugPrint(buff.toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void logDebug(message, [Object? exception, StackTrace? stackTrace]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final buff = StringBuffer("[DUIT FRAMEWORK] DEBUG: $message \nTime: ${DateTime.now().toUtc()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (exception != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nException: ${exception.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stackTrace != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| debugPrint(buff.toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void logError(message, [Object? exception, StackTrace? stackTrace]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final buff = StringBuffer("[DUIT FRAMEWORK] ERROR: $message \nTime: ${DateTime.now().toUtc()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (exception != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nException: ${exception.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stackTrace != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| debugPrint(buff.toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void logInfo(message, [Object? exception, StackTrace? stackTrace]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final buff = StringBuffer("[DUIT FRAMEWORK] INFO: $message \nTime: ${DateTime.now().toUtc()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (exception != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nException: ${exception.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stackTrace != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| debugPrint(buff.toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void logVerbose(message, [Object? exception, StackTrace? stackTrace]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final buff = StringBuffer("[DUIT FRAMEWORK] VERBOSE: $message \nTime: ${DateTime.now().toUtc()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (exception != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nException: ${exception.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stackTrace != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| debugPrint(buff.toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void logWarning(message, [Object? exception, StackTrace? stackTrace]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final buff = StringBuffer("[DUIT FRAMEWORK] WARNING: $message \nTime: ${DateTime.now().toUtc()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (exception != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nException: ${exception.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stackTrace != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| debugPrint(buff.toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Extract common logging logic to reduce duplication. All six logging methods follow an identical pattern, differing only in the log level label. This creates significant code duplication (~66 lines) that could be reduced to ~20 lines by extracting a common helper method. ♻️ Proposed refactor final class LoggingManager with LoggingCapabilityDelegate {
const LoggingManager();
+ void _log(String level, message, [Object? exception, StackTrace? stackTrace]) {
+ final buff = StringBuffer("[DUIT FRAMEWORK] $level: $message \nTime: ${DateTime.now().toUtc()}");
+ if (exception != null) {
+ buff.write("\nException: ${exception.toString()}");
+ }
+ if (stackTrace != null) {
+ buff.write("\nStackTrace: ${stackTrace.toString()}");
+ }
+ debugPrint(buff.toString());
+ }
+
@override
- void logCritical(message, [Object? exception, StackTrace? stackTrace]) {
- final buff = StringBuffer("[DUIT FRAMEWORK] CRITICAL: $message \nTime: ${DateTime.now().toUtc()}");
- if (exception != null) {
- buff.write("\nException: ${exception.toString()}");
- }
- if (stackTrace != null) {
- buff.write("\nStackTrace: ${stackTrace.toString()}");
- }
- debugPrint(buff.toString());
- }
+ void logCritical(message, [Object? exception, StackTrace? stackTrace]) =>
+ _log("CRITICAL", message, exception, stackTrace);
@override
- void logDebug(message, [Object? exception, StackTrace? stackTrace]) {
- final buff = StringBuffer("[DUIT FRAMEWORK] DEBUG: $message \nTime: ${DateTime.now().toUtc()}");
- if (exception != null) {
- buff.write("\nException: ${exception.toString()}");
- }
- if (stackTrace != null) {
- buff.write("\nStackTrace: ${stackTrace.toString()}");
- }
- debugPrint(buff.toString());
- }
+ void logDebug(message, [Object? exception, StackTrace? stackTrace]) =>
+ _log("DEBUG", message, exception, stackTrace);
@override
- void logError(message, [Object? exception, StackTrace? stackTrace]) {
- final buff = StringBuffer("[DUIT FRAMEWORK] ERROR: $message \nTime: ${DateTime.now().toUtc()}");
- if (exception != null) {
- buff.write("\nException: ${exception.toString()}");
- }
- if (stackTrace != null) {
- buff.write("\nStackTrace: ${stackTrace.toString()}");
- }
- debugPrint(buff.toString());
- }
+ void logError(message, [Object? exception, StackTrace? stackTrace]) =>
+ _log("ERROR", message, exception, stackTrace);
@override
- void logInfo(message, [Object? exception, StackTrace? stackTrace]) {
- final buff = StringBuffer("[DUIT FRAMEWORK] INFO: $message \nTime: ${DateTime.now().toUtc()}");
- if (exception != null) {
- buff.write("\nException: ${exception.toString()}");
- }
- if (stackTrace != null) {
- buff.write("\nStackTrace: ${stackTrace.toString()}");
- }
- debugPrint(buff.toString());
- }
+ void logInfo(message, [Object? exception, StackTrace? stackTrace]) =>
+ _log("INFO", message, exception, stackTrace);
@override
- void logVerbose(message, [Object? exception, StackTrace? stackTrace]) {
- final buff = StringBuffer("[DUIT FRAMEWORK] VERBOSE: $message \nTime: ${DateTime.now().toUtc()}");
- if (exception != null) {
- buff.write("\nException: ${exception.toString()}");
- }
- if (stackTrace != null) {
- buff.write("\nStackTrace: ${stackTrace.toString()}");
- }
- debugPrint(buff.toString());
- }
+ void logVerbose(message, [Object? exception, StackTrace? stackTrace]) =>
+ _log("VERBOSE", message, exception, stackTrace);
@override
- void logWarning(message, [Object? exception, StackTrace? stackTrace]) {
- final buff = StringBuffer("[DUIT FRAMEWORK] WARNING: $message \nTime: ${DateTime.now().toUtc()}");
- if (exception != null) {
- buff.write("\nException: ${exception.toString()}");
- }
- if (stackTrace != null) {
- buff.write("\nStackTrace: ${stackTrace.toString()}");
- }
- debugPrint(buff.toString());
- }
+ void logWarning(message, [Object? exception, StackTrace? stackTrace]) =>
+ _log("WARNING", message, exception, stackTrace);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import "package:duit_kernel/src/misc/error.dart"; | ||
| import "package:meta/meta.dart"; | ||
|
|
||
| /// A mixin that provides logging capabilities compatible with Talker API. | ||
| /// | ||
| /// This mixin defines methods for logging messages at different levels, | ||
| /// handling exceptions, and logging custom log types. All methods must be | ||
| /// overridden by implementing classes. | ||
| mixin LoggingCapabilityDelegate { | ||
| /// Logs an informational message. | ||
| /// | ||
| /// Use this method to log general informational messages about the | ||
| /// application's state or flow. | ||
| @mustBeOverridden | ||
| void logInfo( | ||
| message, [ | ||
| Object? exception, | ||
| StackTrace? stackTrace, | ||
| ]) => | ||
| throw const MissingCapabilityMethodImplementation( | ||
| "info", | ||
| "LoggingCapabilityDelegate", | ||
| ); | ||
|
Comment on lines
+15
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Add type annotation to the message parameter. The ♻️ Suggested fix @mustBeOverridden
void logInfo(
- message, [
+ Object? message, [
Object? exception,
StackTrace? stackTrace,
]) =>Apply the same change to all logging methods (logDebug, logWarning, logError, logCritical, logVerbose). 🤖 Prompt for AI Agents |
||
|
|
||
| /// Logs a debug message. | ||
| /// | ||
| /// Use this method to log detailed debugging information that is typically | ||
| /// only useful during development. | ||
| @mustBeOverridden | ||
| void logDebug( | ||
| message, [ | ||
| Object? exception, | ||
| StackTrace? stackTrace, | ||
| ]) => | ||
| throw const MissingCapabilityMethodImplementation( | ||
| "debug", | ||
| "LoggingCapabilityDelegate", | ||
| ); | ||
|
|
||
| /// Logs a warning message. | ||
| /// | ||
| /// Use this method to log warnings about potential issues or unexpected | ||
| /// conditions that don't prevent the application from functioning. | ||
| @mustBeOverridden | ||
| void logWarning( | ||
| message, [ | ||
| Object? exception, | ||
| StackTrace? stackTrace, | ||
| ]) => | ||
| throw const MissingCapabilityMethodImplementation( | ||
| "warning", | ||
| "LoggingCapabilityDelegate", | ||
| ); | ||
|
|
||
| /// Logs an error message. | ||
| /// | ||
| /// Use this method to log error messages that indicate problems or failures | ||
| /// in the application. | ||
| @mustBeOverridden | ||
| void logError( | ||
| message, [ | ||
| Object? exception, | ||
| StackTrace? stackTrace, | ||
| ]) => | ||
| throw const MissingCapabilityMethodImplementation( | ||
| "error", | ||
| "LoggingCapabilityDelegate", | ||
| ); | ||
|
|
||
| /// Logs a critical error message. | ||
| /// | ||
| /// Use this method to log critical errors that require immediate attention | ||
| /// and may indicate serious problems in the application. | ||
| @mustBeOverridden | ||
| void logCritical( | ||
| message, [ | ||
| Object? exception, | ||
| StackTrace? stackTrace, | ||
| ]) => | ||
| throw const MissingCapabilityMethodImplementation( | ||
| "critical", | ||
| "LoggingCapabilityDelegate", | ||
| ); | ||
|
|
||
| /// Logs a verbose message. | ||
| /// | ||
| /// Use this method to log very detailed information that is typically only | ||
| /// useful for deep debugging or troubleshooting. | ||
| @mustBeOverridden | ||
| void logVerbose( | ||
| message, [ | ||
| Object? exception, | ||
| StackTrace? stackTrace, | ||
| ]) => | ||
| throw const MissingCapabilityMethodImplementation( | ||
| "verbose", | ||
| "LoggingCapabilityDelegate", | ||
| ); | ||
| } | ||
|
Comment on lines
+9
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider using abstract methods instead of throwing implementations. The mixin uses concrete methods that throw Alternative approach using abstract methodsmixin LoggingCapabilityDelegate {
/// Logs an informational message.
void logInfo(Object? message, [Object? exception, StackTrace? stackTrace]);
/// Logs a debug message.
void logDebug(Object? message, [Object? exception, StackTrace? stackTrace]);
// ... etc for all methods
}This would enforce implementation at compile-time rather than runtime. 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import "dart:js_interop"; | ||
|
|
||
| import "package:duit_kernel/src/capabilities/logging/logging_capability.dart"; | ||
| import "package:web/web.dart"; | ||
|
|
||
| /// A class that provides logging capabilities for the Duit UI system. | ||
| /// | ||
| /// This class implements the [LoggingCapabilityDelegate] mixin and provides | ||
| /// concrete implementations for logging messages at different levels. | ||
| final class LoggingManager with LoggingCapabilityDelegate { | ||
| const LoggingManager(); | ||
|
|
||
|
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Inconsistent spacing after class declaration. There's an extra blank line after the const constructor at line 8. While minor, consistent formatting improves readability. 🤖 Prompt for AI Agents |
||
| @override | ||
| void logCritical(message, [Object? exception, StackTrace? stackTrace]) { | ||
| final buff = StringBuffer("[DUIT FRAMEWORK] CRITICAL: $message \nTime: ${DateTime.now().toIso8601String()}"); | ||
lesleysin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (exception != null) { | ||
| buff.write("\nException: ${exception.toString()}"); | ||
| } | ||
| if (stackTrace != null) { | ||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||
| } | ||
| console.error(buff.toString().toJS); | ||
| } | ||
|
Comment on lines
+14
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial logCritical and logError both use console.error. Both Alternatively, if browser console limitations mean they must use the same method, document this behavior to set expectations for users debugging in the browser console. Also applies to: 34-43 |
||
|
|
||
| @override | ||
| void logDebug(message, [Object? exception, StackTrace? stackTrace]) { | ||
| final buff = StringBuffer("[DUIT FRAMEWORK] DEBUG: $message \nTime: ${DateTime.now().toIso8601String()}"); | ||
| if (exception != null) { | ||
| buff.write("\nException: ${exception.toString()}"); | ||
| } | ||
| if (stackTrace != null) { | ||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||
| } | ||
| console.debug(buff.toString().toJS); | ||
| } | ||
|
|
||
| @override | ||
| void logError(message, [Object? exception, StackTrace? stackTrace]) { | ||
| final buff = StringBuffer("[DUIT FRAMEWORK] ERROR: $message \nTime: ${DateTime.now().toIso8601String()}"); | ||
| if (exception != null) { | ||
| buff.write("\nException: ${exception.toString()}"); | ||
| } | ||
| if (stackTrace != null) { | ||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||
| } | ||
| console.error(buff.toString().toJS); | ||
| } | ||
|
|
||
| @override | ||
| void logInfo(message, [Object? exception, StackTrace? stackTrace]) { | ||
| final buff = StringBuffer("[DUIT FRAMEWORK] INFO: $message \nTime: ${DateTime.now().toIso8601String()}"); | ||
| if (exception != null) { | ||
| buff.write("\nException: ${exception.toString()}"); | ||
| } | ||
| if (stackTrace != null) { | ||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||
| } | ||
| console.info(buff.toString().toJS); | ||
| } | ||
|
|
||
| @override | ||
| void logVerbose(message, [Object? exception, StackTrace? stackTrace]) { | ||
| final buff = StringBuffer("[DUIT FRAMEWORK] VERBOSE: $message \nTime: ${DateTime.now().toIso8601String()}"); | ||
| if (exception != null) { | ||
| buff.write("\nException: ${exception.toString()}"); | ||
| } | ||
| if (stackTrace != null) { | ||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||
| } | ||
| console.log(buff.toString().toJS); | ||
| } | ||
|
|
||
| @override | ||
| void logWarning(message, [Object? exception, StackTrace? stackTrace]) { | ||
| final buff = StringBuffer("[DUIT FRAMEWORK] WARNING: $message \nTime: ${DateTime.now().toIso8601String()}"); | ||
| if (exception != null) { | ||
| buff.write("\nException: ${exception.toString()}"); | ||
| } | ||
| if (stackTrace != null) { | ||
| buff.write("\nStackTrace: ${stackTrace.toString()}"); | ||
| } | ||
| console.warn(buff.toString().toJS); | ||
| } | ||
|
Comment on lines
+14
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial High code duplication across logging methods. All six logging methods follow an identical pattern, differing only in the log level prefix and console method. Consider extracting the common logic to a helper method to improve maintainability. ♻️ Refactored approachvoid _log(
String level,
void Function(JSString) consoleFn,
Object? message, [
Object? exception,
StackTrace? stackTrace,
]) {
final buff = StringBuffer("[DUIT FRAMEWORK] $level: $message \nTime: ${DateTime.now().toIso8601String()}");
if (exception != null) {
buff.write("\nException: $exception");
}
if (stackTrace != null) {
buff.write("\nStackTrace: $stackTrace");
}
consoleFn(buff.toString().toJS);
}
@override
void logInfo(message, [Object? exception, StackTrace? stackTrace]) {
_log("INFO", console.info, message, exception, stackTrace);
}
@override
void logError(message, [Object? exception, StackTrace? stackTrace]) {
_log("ERROR", console.error, message, exception, stackTrace);
}
// ... etcNote: The 🤖 Prompt for AI Agents |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical logic error: Inverted null check.
The condition checks
if (driver.externalEventHandler != null)but then logs and throws an error stating the handler is NOT set. This logic is inverted—the error should only be thrown when the handler IS null.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents