Skip to content
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

Non-fatal error reporter #91

Merged
merged 3 commits into from
Jun 11, 2024
Merged

Non-fatal error reporter #91

merged 3 commits into from
Jun 11, 2024

Conversation

ubfelix
Copy link
Contributor

@ubfelix ubfelix commented Jun 11, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a non-fatal error reporting system to improve error handling without crashing the app.
  • Bug Fixes

    • Replaced fatalError with assertionFailure and non-fatal error reporting to prevent app crashes during invalid state transitions.

Copy link

coderabbitai bot commented Jun 11, 2024

Walkthrough

The recent changes introduce a new error handling mechanism in the codebase. A UBNonFatalErrorReporter struct is added to handle non-fatal errors gracefully. This struct includes a static handler property for error handling and a report function to trigger the error handling logic. Additionally, in the UBURLDataTask class, a fatalError call is replaced with assertionFailure and the new error reporting mechanism.

Changes

File Path Change Summary
Sources/UBFoundation/Logging/UBNonFatalErrorReporter.swift Introduced UBNonFatalErrorReporter struct with error handling capabilities.
Sources/UBFoundation/Networking/UBURLDataTask.swift Replaced fatalError with assertionFailure and reported the error using UBNonFatalErrorReporter.

Sequence Diagram(s)

sequenceDiagram
    participant Task as UBURLDataTask
    participant Reporter as UBNonFatalErrorReporter
    participant Handler as ErrorHandler

    Task->>Task: Invalid state transition
    Task->>Task: assertionFailure
    Task->>Reporter: report(NSError)
    Reporter->>Handler: Execute handler closure
Loading

Poem

In the code where errors hide,
A rabbit hops with gentle stride.
Fatal flaws now softly caught,
Non-fatal errors, a safer thought.
With handlers set to catch and mend,
Our code's journey finds no end.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6714c30 and 1b2aaf4.

Files selected for processing (2)
  • Sources/UBFoundation/Logging/UBNonFatalErrorReporter.swift (1 hunks)
  • Sources/UBFoundation/Networking/UBURLDataTask.swift (1 hunks)
Additional context used
SwiftLint
Sources/UBFoundation/Logging/UBNonFatalErrorReporter.swift

[Warning] 10-10: Types used for hosting only static members should be implemented as a caseless enum to avoid instantiation (convenience_type)

Sources/UBFoundation/Networking/UBURLDataTask.swift

[Warning] 199-199: Conditional statements should always return on the next line (conditional_returns_on_newline)


[Warning] 871-871: File should contain 400 lines or less: currently contains 871 (file_length)


[Warning] 303-303: Force unwrapping should be avoided (force_unwrapping)


[Warning] 309-309: Force unwrapping should be avoided (force_unwrapping)


[Warning] 867-867: Function should have 5 parameters or less: it currently has 6 (function_parameter_count)


[Error] 80-80: Variable name 'q' should be between 3 and 40 characters long (identifier_name)


[Error] 183-183: Variable name 'r' should be between 3 and 40 characters long (identifier_name)


[Error] 557-557: Tuples should have at most 2 members (large_tuple)


[Error] 562-562: Tuples should have at most 2 members (large_tuple)


[Error] 598-598: Tuples should have at most 2 members (large_tuple)


[Error] 603-603: Tuples should have at most 2 members (large_tuple)


[Warning] 47-47: Line should be 120 characters or less; currently it has 170 characters (line_length)


[Warning] 98-98: Line should be 120 characters or less; currently it has 140 characters (line_length)


[Error] 100-100: Line should be 200 characters or less; currently it has 233 characters (line_length)


[Warning] 103-103: Line should be 120 characters or less; currently it has 164 characters (line_length)


[Warning] 105-105: Line should be 120 characters or less; currently it has 184 characters (line_length)


[Error] 107-107: Line should be 200 characters or less; currently it has 206 characters (line_length)


[Error] 108-108: Line should be 200 characters or less; currently it has 219 characters (line_length)


[Warning] 122-122: Line should be 120 characters or less; currently it has 140 characters (line_length)


[Error] 124-124: Line should be 200 characters or less; currently it has 233 characters (line_length)


[Warning] 129-129: Line should be 120 characters or less; currently it has 184 characters (line_length)


[Error] 131-131: Line should be 200 characters or less; currently it has 238 characters (line_length)


[Error] 132-132: Line should be 200 characters or less; currently it has 218 characters (line_length)


[Warning] 133-133: Line should be 120 characters or less; currently it has 152 characters (line_length)


[Warning] 201-201: Line should be 120 characters or less; currently it has 140 characters (line_length)


[Warning] 230-230: Line should be 120 characters or less; currently it has 160 characters (line_length)


[Warning] 240-240: Line should be 120 characters or less; currently it has 140 characters (line_length)


[Warning] 358-358: Line should be 120 characters or less; currently it has 175 characters (line_length)


[Warning] 363-363: Line should be 120 characters or less; currently it has 122 characters (line_length)


[Warning] 435-435: Line should be 120 characters or less; currently it has 146 characters (line_length)


[Warning] 469-469: Line should be 120 characters or less; currently it has 127 characters (line_length)


[Warning] 519-519: Line should be 120 characters or less; currently it has 144 characters (line_length)


[Warning] 521-521: Line should be 120 characters or less; currently it has 157 characters (line_length)


[Warning] 538-538: Line should be 120 characters or less; currently it has 131 characters (line_length)


[Warning] 540-540: Line should be 120 characters or less; currently it has 173 characters (line_length)


[Warning] 546-546: Line should be 120 characters or less; currently it has 165 characters (line_length)


[Warning] 557-557: Line should be 120 characters or less; currently it has 195 characters (line_length)


[Warning] 564-564: Line should be 120 characters or less; currently it has 132 characters (line_length)


[Warning] 574-574: Line should be 120 characters or less; currently it has 124 characters (line_length)


[Warning] 598-598: Line should be 120 characters or less; currently it has 163 characters (line_length)


[Warning] 605-605: Line should be 120 characters or less; currently it has 137 characters (line_length)


[Warning] 615-615: Line should be 120 characters or less; currently it has 124 characters (line_length)


[Warning] 640-640: Line should be 120 characters or less; currently it has 152 characters (line_length)


[Warning] 658-658: Line should be 120 characters or less; currently it has 178 characters (line_length)


[Warning] 659-659: Line should be 120 characters or less; currently it has 125 characters (line_length)


[Error] 678-678: Line should be 200 characters or less; currently it has 244 characters (line_length)


[Warning] 679-679: Line should be 120 characters or less; currently it has 153 characters (line_length)


[Warning] 716-716: Line should be 120 characters or less; currently it has 122 characters (line_length)


[Warning] 728-728: Line should be 120 characters or less; currently it has 122 characters (line_length)


[Warning] 738-738: Line should be 120 characters or less; currently it has 122 characters (line_length)


[Error] 754-754: Line should be 200 characters or less; currently it has 222 characters (line_length)


[Warning] 782-782: Line should be 120 characters or less; currently it has 121 characters (line_length)


[Warning] 783-783: Line should be 120 characters or less; currently it has 140 characters (line_length)


[Warning] 787-787: Line should be 120 characters or less; currently it has 133 characters (line_length)


[Warning] 812-812: Line should be 120 characters or less; currently it has 199 characters (line_length)


[Warning] 862-862: Line should be 120 characters or less; currently it has 142 characters (line_length)


[Warning] 867-867: Line should be 120 characters or less; currently it has 169 characters (line_length)


[Warning] 193-193: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 195-195: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 242-242: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 246-246: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 276-276: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 278-278: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 396-396: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 398-398: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 400-400: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 402-402: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 404-404: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 406-406: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 419-419: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 432-432: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 765-765: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 767-767: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 770-770: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Warning] 772-772: Case statements should vertically aligned with their closing brace (switch_case_alignment)


[Error] 11-11: Type body should span 350 lines or less excluding comments and whitespace: currently spans 456 lines (type_body_length)

Comment on lines 10 to 16
public struct UBNonFatalErrorReporter {
public static var handler: ((Error) -> Void)?

static func report(_ error: Error) {
handler?(error)
}
}
Copy link

Choose a reason for hiding this comment

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

Refactor UBNonFatalErrorReporter to a caseless enum to prevent instantiation.

public enum UBNonFatalErrorReporter {
    public static var handler: ((Error) -> Void)?
    public static func report(_ error: Error) {
        handler?(error)
    }
}
Tools
SwiftLint

[Warning] 10-10: Types used for hosting only static members should be implemented as a caseless enum to avoid instantiation (convenience_type)

Comment on lines +433 to +435
let errorMessage = "Invalid state transition from \(_state) -> \(newValue)"
assertionFailure(errorMessage)
UBNonFatalErrorReporter.report(NSError(domain: "UBURLDataTask", code: 0, userInfo: [NSLocalizedDescriptionKey: errorMessage]))
Copy link

Choose a reason for hiding this comment

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

Improve error handling by encapsulating error creation.

let errorMessage = "Invalid state transition from \(_state) -> \(newValue)"
assertionFailure(errorMessage)
UBNonFatalErrorReporter.report(createError(withMessage: errorMessage))

// Suggested helper function
private func createError(withMessage message: String) -> NSError {
    return NSError(domain: "UBURLDataTask", code: 0, userInfo: [NSLocalizedDescriptionKey: message])
}
Tools
SwiftLint

[Warning] 435-435: Line should be 120 characters or less; currently it has 146 characters (line_length)

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b2aaf4 and 3b437db.

Files selected for processing (1)
  • Sources/UBFoundation/Logging/UBNonFatalErrorReporter.swift (1 hunks)
Files skipped from review due to trivial changes (1)
  • Sources/UBFoundation/Logging/UBNonFatalErrorReporter.swift

@ubfelix ubfelix merged commit 0a4ffce into main Jun 11, 2024
1 of 3 checks passed
@ubfelix ubfelix deleted the feature/nonfatal-error-reporter branch June 11, 2024 15:03
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