Skip to content

Add documentation about Fail fast strategy in android #2697

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

Merged
merged 4 commits into from
Jun 17, 2025

Conversation

TimoPtr
Copy link
Contributor

@TimoPtr TimoPtr commented Jun 12, 2025

Proposed change

Add a new section in best practices for Android about the new FailFast API. It also add more details in the section about writing custom lint rules by adding the current custom rules that we have.

Type of change

  • Document existing features within Home Assistant
  • Document new or changing features for which there is an existing pull request elsewhere
  • Spelling or grammatical corrections, or rewording for improved clarity
  • Changes to the backend of this documentation
  • Remove stale or deprecated documentation

Checklist

  • I have read and followed the documentation guidelines.
  • I have verified that my changes render correctly in the documentation.

Additional information

Summary by CodeRabbit

  • Documentation
    • Expanded Android best practices documentation with a new "Fail fast" section, highlighting early error detection and handling strategies.
    • Updated linter documentation to clarify the use of custom lint rules in the project, including details and an example of a rule for detecting missing serialization annotations.

@TimoPtr TimoPtr requested review from jpelgrom and dshokouhi June 12, 2025 09:22
Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

📝 Walkthrough

Walkthrough

The documentation for Android best practices was updated with a new "Fail fast" section, detailing strategies for early error detection and handling. Additionally, the linter documentation was expanded to clarify the use and organization of custom lint rules, including an example of a custom rule for missing serialization annotations.

Changes

File(s) Change Summary
docs/android/best_practices.md Added "Fail fast" section covering early error detection, Kotlin compiler usage, FailFast API, and example error logging.
docs/android/linter.md Expanded custom lint rules section, added project organization details, and example MissingSerializableAnnotationIssue rule.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant App (Debug Build)
    participant App (Production Build)
    participant FailFast API
    participant Logger

    Developer->>App (Debug Build): Runs code with potential error
    App (Debug Build)->>FailFast API: Error encountered
    FailFast API->>App (Debug Build): Crash app, show error message

    Developer->>App (Production Build): Runs code with potential error
    App (Production Build)->>FailFast API: Error encountered
    FailFast API->>Logger: Log error
    FailFast API->>App (Production Build): Return fallback value
Loading
sequenceDiagram
    participant Developer
    participant Lint Module
    participant Custom Rule (MissingSerializableAnnotationIssue)

    Developer->>Lint Module: Runs lint checks
    Lint Module->>Custom Rule: Analyze code for @Serializable
    Custom Rule->>Lint Module: Report missing annotation issues
    Lint Module->>Developer: Show lint warnings/errors
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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
Contributor

@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

🧹 Nitpick comments (2)
docs/android/linter.md (1)

144-147: Clarify or link the :lint module
Mentioning the dedicated Gradle module is great—consider adding a hyperlink to the module’s directory in the repo for quick navigation (e.g., “see the :lint module on GitHub”).

docs/android/best_practices.md (1)

185-187: Refine wording for formality
Consider replacing “identify, debug, and fix issues” with “identify, troubleshoot, and resolve issues” for a more formal tone.

🧰 Tools
🪛 LanguageTool

[style] ~186-~186: Consider using a different verb for a more formal wording.
Context: ...make it easier to identify, debug, and fix issues before they reach production. W...

(FIX_RESOLVE)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 41fc4de and 32b9e2b.

📒 Files selected for processing (2)
  • docs/android/best_practices.md (1 hunks)
  • docs/android/linter.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/android/best_practices.md

[style] ~149-~149: Consider a different adjective to strengthen your wording.
Context: ...rashes, silently ignoring them can hide deeper issues and make debugging more difficul...

(DEEP_PROFOUND)


[style] ~186-~186: Consider using a different verb for a more formal wording.
Context: ...make it easier to identify, debug, and fix issues before they reach production. W...

(FIX_RESOLVE)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - developers-home-assistant
  • GitHub Check: Header rules - developers-home-assistant
  • GitHub Check: Pages changed - developers-home-assistant
🔇 Additional comments (3)
docs/android/linter.md (2)

142-143: Nice addition: call to contribute custom rules
Encouraging contributions here aligns well with the project’s philosophy of enforcing domain-specific patterns early.


148-148: Good concrete example
The MissingSerializableAnnotationIssue bullet clearly communicates the rule’s purpose and ties back to serialization best practices.

docs/android/best_practices.md (1)

120-124: Approve new “Fail fast” section—verify navigation
The new section on fail-fast strategies fills an important gap. Ensure that this heading appears in the Android docs sidebar or table of contents so readers can find it easily.

Co-authored-by: Martin Hjelmare <[email protected]>
MartinHjelmare
MartinHjelmare previously approved these changes Jun 12, 2025
Copy link
Member

@jpelgrom jpelgrom left a comment

Choose a reason for hiding this comment

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

After thinking how I would respond if someone submitted the examples in a PR, a few suggestions for the code and to make it easier to understand without looking at the FailFast functions first.

Copy link
Contributor

@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

♻️ Duplicate comments (1)
docs/android/best_practices.md (1)

169-184: Fix grammar and align error message
In the FailFast.failOnCatch example, update the message to match the earlier Timber.w log and correct the tense (e.g., "External third party threw an error. Current state = …").

🧹 Nitpick comments (4)
docs/android/best_practices.md (4)

120-124: Prefer stronger phrasing for compile-time checks
Consider updating “Always aim to catch errors at build time rather than at runtime” to “Opt for compile-time checks (e.g., via Kotlin compiler plugins or custom lint rules) whenever possible” to strengthen the recommendation.


147-168: Catch specific exceptions
Catching Exception can mask unexpected errors. Consider catching only the exceptions you expect (e.g., IOException or a custom API exception) to avoid hiding programming issues.

🧰 Tools
🪛 LanguageTool

[style] ~149-~149: Consider a different adjective to strengthen your wording.
Context: ...rashes, silently ignoring them can hide deeper issues and make debugging more difficul...

(DEEP_PROFOUND)


186-188: Use “resolve” instead of “fix”
Replace “debug, and fix issues” with “debug, and resolve issues” for a more formal tone.

🧰 Tools
🪛 LanguageTool

[style] ~187-~187: Consider using a different verb for a more formal wording.
Context: ...make it easier to identify, debug, and fix issues before they reach production. W...

(FIX_RESOLVE)


191-206: Remove hard tabs in log block
The sample log contains hard tab characters that markdownlint flags. Convert them to spaces for consistent formatting.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

205-205: Hard tabs
Column: 101

(MD010, no-hard-tabs)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 0c62274 and b00a606.

📒 Files selected for processing (1)
  • docs/android/best_practices.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/android/best_practices.md

[style] ~149-~149: Consider a different adjective to strengthen your wording.
Context: ...rashes, silently ignoring them can hide deeper issues and make debugging more difficul...

(DEEP_PROFOUND)


[style] ~187-~187: Consider using a different verb for a more formal wording.
Context: ...make it easier to identify, debug, and fix issues before they reach production. W...

(FIX_RESOLVE)

🪛 markdownlint-cli2 (0.17.2)
docs/android/best_practices.md

205-205: Hard tabs
Column: 101

(MD010, no-hard-tabs)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - developers-home-assistant
  • GitHub Check: Header rules - developers-home-assistant
  • GitHub Check: Pages changed - developers-home-assistant
🔇 Additional comments (1)
docs/android/best_practices.md (1)

125-145: Good Kotlin compiler example
The sealed when snippet correctly demonstrates exhaustive checks without an else branch and is clear for readers.

@TimoPtr TimoPtr requested a review from jpelgrom June 16, 2025 07:50
Copy link
Contributor

@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

🧹 Nitpick comments (4)
docs/android/best_practices.md (4)

121-121: Section header casing consistency
The heading ## Fail fast should match the title‐casing style of other sections. Consider renaming to ## Fail Fast or ## Fail-Fast for consistency.


147-151: Strengthen exception-handling wording
The phrase

“silently ignoring them can hide deeper issues and make debugging more difficult”
could be more impactful. For example:

- silently ignoring them can hide deeper issues and make debugging more difficult
+ silently ignoring them can obscure root causes and hamper effective debugging
🧰 Tools
🪛 LanguageTool

[style] ~149-~149: Consider a different adjective to strengthen your wording.
Context: ...rashes, silently ignoring them can hide deeper issues and make debugging more difficul...

(DEEP_PROFOUND)


189-191: Formal tone for “fix”
For a more formal tone, consider replacing “fix” with “resolve”:

- debug, and fix issues before they reach production.
+ debug, and resolve issues before they reach production.
🧰 Tools
🪛 LanguageTool

[style] ~190-~190: Consider using a different verb for a more formal wording.
Context: ...make it easier to identify, debug, and fix issues before they reach production. W...

(FIX_RESOLVE)


194-209: Remove hard tabs from log snippet
The log block contains hard-tab characters (e.g., line 208), which violates MD010. Replace leading tabs with spaces:

-	2025-06-12 10:53:20.841 29743-29743 CrashFailFastHandler …
+    2025-06-12 10:53:20.841 29743-29743 CrashFailFastHandler …
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

208-208: Hard tabs
Column: 101

(MD010, no-hard-tabs)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between b00a606 and 404f222.

📒 Files selected for processing (1)
  • docs/android/best_practices.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/android/best_practices.md

[style] ~149-~149: Consider a different adjective to strengthen your wording.
Context: ...rashes, silently ignoring them can hide deeper issues and make debugging more difficul...

(DEEP_PROFOUND)


[style] ~190-~190: Consider using a different verb for a more formal wording.
Context: ...make it easier to identify, debug, and fix issues before they reach production. W...

(FIX_RESOLVE)

🪛 markdownlint-cli2 (0.17.2)
docs/android/best_practices.md

208-208: Hard tabs
Column: 101

(MD010, no-hard-tabs)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - developers-home-assistant
  • GitHub Check: Header rules - developers-home-assistant
  • GitHub Check: Pages changed - developers-home-assistant
🔇 Additional comments (4)
docs/android/best_practices.md (4)

122-124: Intro paragraph is clear
This introduction effectively communicates the importance of catching errors early and links to the lint documentation for compile-time checks.


127-135: Kotlin compiler example is accurate
The sealed-interface when example correctly illustrates exhaustive checks with no else branch.


153-164: Logging example is solid
This snippet correctly shows catching the exception, logging with context, and providing a fallback.


174-187: FailFast API usage is clear
The FailFast.failOnCatch example succinctly demonstrates crash-in-debug vs. fallback-in-prod behavior.

@TimoPtr TimoPtr merged commit de4054f into master Jun 17, 2025
5 checks passed
@TimoPtr TimoPtr deleted the feature/fail_fast branch June 17, 2025 12:14
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.

3 participants