Skip to content

Avoid caching when JQ filter call fails#191

Merged
frenck merged 2 commits intohassio-addons:mainfrom
lmagyar:pr-fix-jq-calls
Apr 7, 2026
Merged

Avoid caching when JQ filter call fails#191
frenck merged 2 commits intohassio-addons:mainfrom
lmagyar:pr-fix-jq-calls

Conversation

@lmagyar
Copy link
Copy Markdown
Contributor

@lmagyar lmagyar commented Jan 31, 2026

Proposed Changes

This is a continuation of #164 and #168.

I've added this protection only to those locations, where there is a "user" supported filter.

This was catched by coderabbitai here: #188 (comment)

Related Issues

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for data filtering operations across multiple system modules. The system now validates filter execution and immediately reports errors when filters fail, preventing silent propagation of invalid data. This enhances reliability and provides clearer diagnostic messages for troubleshooting.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 31, 2026

Walkthrough

Systematic addition of error handling for jq filter operations across multiple library files. When a jq filter fails, the code now logs an error "Failed to execute the jq filter" and returns a non-zero exit code, preventing further processing with potentially invalid data.

Changes

Cohort / File(s) Summary
jq Filter Error Handling
lib/addons.sh, lib/api.sh, lib/hardware.sh, lib/host.sh, lib/info.sh, lib/os.sh
Added exit status checks after jq filter execution in single functions. On filter failure, logs error and returns __BASHIO_EXIT_NOK.
jq Filter Error Handling
lib/audio.sh, lib/cli.sh, lib/core.sh, lib/dns.sh, lib/multicast.sh, lib/network.sh, lib/observer.sh, lib/supervisor.sh
Added exit status checks after jq filter execution in dual functions (e.g., main and .stats variants). On filter failure, logs error and returns __BASHIO_EXIT_NOK.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

bugfix

Suggested reviewers

  • frenck
  • sairon

Poem

🐰 Through bashio's halls, a careful check I made,
When jq filters stumble, errors are displayed,
No silent failures in the night so deep,
Just truthful returns and logs to keep,
The code runs honest, clear, and free! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the changeset, which adds error handling and avoids caching when jq filter operations fail across multiple shell script files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Mar 3, 2026
@lmagyar
Copy link
Copy Markdown
Contributor Author

lmagyar commented Mar 3, 2026

not stale

@github-actions github-actions bot removed the stale There has not been activity on this issue or PR for quite some time. label Mar 4, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Apr 3, 2026
@lmagyar
Copy link
Copy Markdown
Contributor Author

lmagyar commented Apr 3, 2026

not stale

@github-actions github-actions bot removed the stale There has not been activity on this issue or PR for quite some time. label Apr 4, 2026
@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementors. label Apr 7, 2026
@frenck frenck requested a review from Copilot April 7, 2026 13:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens Bashio’s “user-provided jq filter” paths by detecting jq execution failures and aborting early, so failed filter evaluations don’t end up cached (or silently propagated) across subsequent calls.

Changes:

  • Add return-code checks after bashio::jq calls and return __BASHIO_EXIT_NOK on filter failures.
  • Prevent bashio::cache.set from running when jq filter execution fails in the affected cached-info helpers.
  • Apply the same jq-failure handling to bashio::api.supervisor()’s optional filter step.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/supervisor.sh Stop and return error when jq filtering fails before caching supervisor info/stats.
lib/os.sh Stop and return error when jq filtering fails before caching OS info.
lib/observer.sh Stop and return error when jq filtering fails before caching observer info/stats.
lib/network.sh Stop and return error when jq filtering fails before caching network info/interface info.
lib/multicast.sh Stop and return error when jq filtering fails before caching multicast info/stats.
lib/info.sh Stop and return error when jq filtering fails before caching general system info.
lib/host.sh Stop and return error when jq filtering fails before caching host info.
lib/hardware.sh Stop and return error when jq filtering fails before caching hardware info.
lib/dns.sh Stop and return error when jq filtering fails before caching DNS info/stats.
lib/core.sh Stop and return error when jq filtering fails before caching core info/stats.
lib/cli.sh Stop and return error when jq filtering fails before caching CLI info/stats.
lib/audio.sh Stop and return error when jq filtering fails before caching audio info/stats.
lib/api.sh Return error if optional jq filter application fails in Supervisor API calls.
lib/addons.sh Stop and return error when jq filtering fails before caching add-on stats.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Nice!

Thanks, @lmagyar 👍

../Frenck

                       

Blogging my personal ramblings at frenck.dev

@frenck frenck merged commit 752fa6c into hassio-addons:main Apr 7, 2026
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 2026
@lmagyar lmagyar deleted the pr-fix-jq-calls branch April 13, 2026 09:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants