Skip to content

Conversation

Zekfad
Copy link

@Zekfad Zekfad commented Jun 14, 2025

  • Performance improvement: use initializer instead of late initialization and polymorph getters

  • Bugfix for missing error and exception details
    Describe the bug
    TalkerData#generateTextMessage is missing displayException and displayError, uses message instead of displayMessage which could cause "null" string in logs (intended?).
    TalkerLog#generateTextMessage is missing displayError which prevents printing errors to console log.

    To Reproduce

    • Add custom log with error.
    • Error is not printed.

    Expected behavior

    • Error should be included in output same as exception.

Summary by Sourcery

Fix missing error and exception details in console logs and optimize TalkerData initialization and constructors

Bug Fixes:

  • Include displayException and displayError in generated log messages to ensure errors and exceptions appear in console logs

Enhancements:

  • Replace late initialization and polymorphic getters in TalkerData with constructor initializers for better performance
  • Simplify TalkerException and TalkerError constructors by forwarding parameters to super and defaulting key and logLevel

Zekfad added 2 commits June 14, 2025 16:25
…tters

this will remove late initialization checks from runtime and unnecessary
getter overloads, which will also make classes more friendly to extension
Copy link
Contributor

sourcery-ai bot commented Jun 14, 2025

Reviewer's Guide

Refactors initialization to use constructor initializers instead of late initialization, streamlines constructors for exception and error models, and ensures error/exception details are included in generated console messages.

Sequence Diagram for Updated TalkerData Message Generation

sequenceDiagram
    title Sequence Diagram: Updated TalkerData.generateTextMessage
    participant C as Caller
    participant TD as "TalkerData"

    C->>TD: generateTextMessage(timeFormat)
    activate TD
    TD->>TD: displayTitleWithTime(timeFormat)
    TD->>TD: get displayMessage
    TD->>TD: get displayException
    TD->>TD: get displayError
    TD->>TD: get displayStackTrace
    TD-->>C: Constructed Log String
    deactivate TD
Loading

Sequence Diagram for Updated TalkerLog Message Generation

sequenceDiagram
    title Sequence Diagram: Updated TalkerLog.generateTextMessage
    participant C as Caller
    participant TL as "TalkerLog"

    C->>TL: generateTextMessage(timeFormat)
    activate TL
    TL->>TL: displayTitleWithTime(timeFormat)
    TL->>TL: get displayMessage
    TL->>TL: get displayException
    TL->>TL: get displayError
    TL->>TL: get displayStackTrace
    TL-->>C: Constructed Log String
    deactivate TL
Loading

Updated Class Diagram for Talker Models

classDiagram
    class TalkerData {
        +String? message
        +LogLevel? logLevel
        +Exception? exception
        +Error? error
        +StackTrace? stackTrace
        +String? title
        +final DateTime time
        +AnsiPen? pen
        +String? key
        +generateTextMessage(TimeFormat timeFormat) String
    }
    class TalkerException {
        +TalkerException(Exception exception, String? message, StackTrace? stackTrace, String? key, String? title, LogLevel? logLevel)
    }
    class TalkerError {
        +TalkerError(Error error, String? message, StackTrace? stackTrace, String? key, String? title, LogLevel? logLevel)
    }
    class TalkerLog {
        +TalkerLog(String message, LogLevel? logLevel, String? key, String? title, AnsiPen? pen, Exception? exception, Error? error, StackTrace? stackTrace)
        +generateTextMessage(TimeFormat timeFormat) String
    }

    TalkerData <|-- TalkerException
    TalkerData <|-- TalkerError
    TalkerData <|-- TalkerLog
Loading

File-Level Changes

Change Details Files
Refactored TalkerData field initialization to use constructor initializer
  • Removed late-backed _time in favor of final time initialized in constructor
  • Reordered and finalized fields: moved key and title declarations
  • Eliminated late declarations for fields previously requiring polymorphic getters
packages/talker/lib/src/models/talker_data.dart
Streamlined TalkerException and TalkerError constructors
  • Inlined super calls with message, logLevel, exception/error, and key parameters
  • Removed custom _key and _logLevel fields and their overriding getters
packages/talker/lib/src/models/talker_exception.dart
packages/talker/lib/src/models/talker_error.dart
Enhanced text message generation to include missing exception and error outputs
  • Replaced raw message with displayMessage in generateTextMessage
  • Appended displayException and displayError to console output string
  • Applied same fix to TalkerLog’s generateTextMessage
packages/talker/lib/src/models/talker_data.dart
packages/talker/lib/src/models/talker_log.dart
Fixed documentation typo
  • Corrected comment from Exceptionss to Exceptions
packages/talker/lib/src/models/talker_exception.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Zekfad - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `packages/talker/lib/src/models/talker_data.dart:71` </location>
<code_context>
   String generateTextMessage(
       {TimeFormat timeFormat = TimeFormat.timeAndSeconds}) {
-    return '${displayTitleWithTime(timeFormat: timeFormat)}$message$displayStackTrace';
+    return '${displayTitleWithTime(timeFormat: timeFormat)}$displayMessage$displayException$displayError$displayStackTrace';
   }
 }
</code_context>

<issue_to_address>
Missing delimiters between concatenated display segments

Check that each getter adds necessary spacing or newlines, or add explicit delimiters here to prevent segments from merging.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
  String generateTextMessage(
      {TimeFormat timeFormat = TimeFormat.timeAndSeconds}) {
-    return '${displayTitleWithTime(timeFormat: timeFormat)}$displayMessage$displayException$displayError$displayStackTrace';
=======
  String generateTextMessage(
      {TimeFormat timeFormat = TimeFormat.timeAndSeconds}) {
    return '${displayTitleWithTime(timeFormat: timeFormat)}\n'
        '${displayMessage ?? ''}${displayMessage != null ? '\n' : ''}'
        '${displayException ?? ''}${displayException != null ? '\n' : ''}'
        '${displayError ?? ''}${displayError != null ? '\n' : ''}'
        '${displayStackTrace ?? ''}';
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 69 to +71
String generateTextMessage(
{TimeFormat timeFormat = TimeFormat.timeAndSeconds}) {
return '${displayTitleWithTime(timeFormat: timeFormat)}$message$displayStackTrace';
return '${displayTitleWithTime(timeFormat: timeFormat)}$displayMessage$displayException$displayError$displayStackTrace';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Missing delimiters between concatenated display segments

Check that each getter adds necessary spacing or newlines, or add explicit delimiters here to prevent segments from merging.

Suggested change
String generateTextMessage(
{TimeFormat timeFormat = TimeFormat.timeAndSeconds}) {
return '${displayTitleWithTime(timeFormat: timeFormat)}$message$displayStackTrace';
return '${displayTitleWithTime(timeFormat: timeFormat)}$displayMessage$displayException$displayError$displayStackTrace';
String generateTextMessage(
{TimeFormat timeFormat = TimeFormat.timeAndSeconds}) {
return '${displayTitleWithTime(timeFormat: timeFormat)}\n'
'${displayMessage ?? ''}${displayMessage != null ? '\n' : ''}'
'${displayException ?? ''}${displayException != null ? '\n' : ''}'
'${displayError ?? ''}${displayError != null ? '\n' : ''}'
'${displayStackTrace ?? ''}';

@Frezyx
Copy link
Owner

Frezyx commented Jun 29, 2025

@Zekfad Hello! Please make 2 separated PR for each functionality

@Zekfad
Copy link
Author

Zekfad commented Jul 4, 2025

Thanks for feedback! I'll split it in a following week.

@Zekfad Zekfad closed this Jul 16, 2025
@Zekfad
Copy link
Author

Zekfad commented Jul 16, 2025

@Frezyx I've filed #399 and #398.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants