Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions homeassistant/helpers/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def component_translation_file(hass, component, language):
name = component

module = get_component(hass, component)
if module is None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes no sense. get_component is not about things not being setup. It's about loading the component from file, either from your custom components dir or from built-in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, you are forcing me to fix the root cause. Got it.

_LOGGER.warning('component %s is not loaded', component)
return
component_path = path.dirname(module.__file__)

# If loading translations for the package root, (__init__.py), the
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/util/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def load_json(filename: str, default: Union[List, Dict, None] = None) \

Defaults to returning empty dict if file is not found.
"""
if filename is None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is also not good. We should fail. This code should never be called if filename is None.

We should write code that doesn't handle "bad" inputs and tries to fix them. Raise errors instead. The moment we fix them, that function will need to keep fixing it forever, even if other things get added to the function that would allow the previously bad input. The previously bad input expects to be "changed" or else bugs in other code happen.

return {}
try:
with open(filename, encoding='utf-8') as fdesc:
return json.loads(fdesc.read()) # type: ignore
Expand Down