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

Suppress logging stack trace on stable build for HomeAssistantError #101762

Closed
wants to merge 10 commits into from

Conversation

jbouwh
Copy link
Contributor

@jbouwh jbouwh commented Oct 10, 2023

Proposed change

Suppress stack traces on logs raised with HomeAssistantError on stable versions of HomeAssistant and when debug logging is abled (for a specific logger).

Rationale

HomeAssistantError and its subclasses are expected errors which means a stack trace is not warranted. Printing a stack trace is still very helpful during development though. The solution in the PR avoids spamming users with stack traces, while also not obstructing development.

We make it possible to enable logging stack trace for HomeAssistantError also on stable builds when debug level is supported by the logger.

Architectural discussion: home-assistant/architecture#986

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@jbouwh jbouwh marked this pull request as draft October 10, 2023 15:38
@jbouwh jbouwh marked this pull request as ready for review October 10, 2023 16:54
@jbouwh jbouwh requested a review from emontnemery October 10, 2023 16:54
@jbouwh jbouwh marked this pull request as draft October 10, 2023 16:59
@jbouwh jbouwh marked this pull request as ready for review October 10, 2023 17:04
Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @jbouwh 👍

@emontnemery emontnemery added second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. docs-missing labels Oct 11, 2023
@emontnemery
Copy link
Contributor

This is quite a big change, before we merge I'd like:

  • A second opinion
  • If the change is deemed good to go, a blog post introducing the change

tests/util/test_logging.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft October 11, 2023 19:43
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@jbouwh jbouwh marked this pull request as ready for review October 11, 2023 21:11
tests/util/test_logging.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft October 11, 2023 21:12
@jbouwh jbouwh marked this pull request as ready for review October 11, 2023 21:24
@jbouwh
Copy link
Contributor Author

jbouwh commented Oct 11, 2023

Thnx @MartinHjelmare , I'll prepare a blog post

@jbouwh
Copy link
Contributor Author

jbouwh commented Oct 11, 2023

Shouldn't we catch these instead where they end up as traces?? If we print traces for them it means we are not expecting them.

That is an alternative approach. We catch the expected errors in homeassistant/components/websocket_api/commands.py where the message text is send to the frontend. The traces though are assumed to be of interest for development only. For normal users the traces will spam the logs.

@elupus
Copy link
Contributor

elupus commented Oct 11, 2023

If we have places where we print traces for these exceptions, that is a bug. We should find those places and fix them, not hide it globally.

@elupus
Copy link
Contributor

elupus commented Oct 11, 2023

Secondly, if we are interested in the traces we could print traces if debug level logging is on for that specific location where we caught the exception. Again this need to be done where we catch the exception.

@jbouwh
Copy link
Contributor Author

jbouwh commented Oct 11, 2023

If we have places where we print traces for these exceptions, that is a bug. We should find those places and fix them, not hide it globally.

Just to be clear: This PR is not effecting stack traces for unexpected exceptions.

@elupus
Copy link
Contributor

elupus commented Oct 12, 2023

Right, and i say that any place that prints traces for these exceptions are faulty.

@jbouwh
Copy link
Contributor Author

jbouwh commented Oct 12, 2023

Right, and i say that any place that prints traces for these exceptions are faulty.

Okay, all we are effectively doing here is suppressing track prints on known catched errors. All other errors can be assumed caused by bugs, will have a stack trace and should be fixed indeed.

@jbouwh
Copy link
Contributor Author

jbouwh commented Oct 12, 2023

Secondly, to still allow developers to solve caught exceptions, stack traces are still unfiltered for know errors.

@MartinHjelmare MartinHjelmare marked this pull request as draft October 12, 2023 09:46
@MartinHjelmare
Copy link
Member

Drafting so we make sure we're aligned on the next step before going ahead.

@emontnemery
Copy link
Contributor

The implementation is changing, and there's an open architecture issue -> I requested a new review from myself and @MartinHjelmare

@jbouwh jbouwh force-pushed the suppress-logging-on-stable-build branch from 314ca35 to c5e2f7d Compare October 17, 2023 17:01
@jbouwh jbouwh removed the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Oct 20, 2023
@jbouwh
Copy link
Contributor Author

jbouwh commented Oct 20, 2023

Superseeded by #102410

@jbouwh jbouwh closed this Oct 20, 2023
@jbouwh jbouwh deleted the suppress-logging-on-stable-build branch October 20, 2023 18:24
@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants