Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
e7ca6b6e
Unverified
Commit
e7ca6b6e
authored
3 years ago
by
Paulus Schoutsen
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Highlight in logs it is a custom component when setup fails (#67559)
Co-authored-by:
Joakim Sørensen
<
ludeeus@ludeeus.dev
>
parent
a55d20f1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/setup.py
+13
-5
13 additions, 5 deletions
homeassistant/setup.py
tests/test_setup.py
+17
-0
17 additions, 0 deletions
tests/test_setup.py
with
30 additions
and
5 deletions
homeassistant/setup.py
+
13
−
5
View file @
e7ca6b6e
...
@@ -149,10 +149,17 @@ async def _async_setup_component(
...
@@ -149,10 +149,17 @@ async def _async_setup_component(
This method is a coroutine.
This method is a coroutine.
"""
"""
integration
:
loader
.
Integration
|
None
=
None
def
log_error
(
msg
:
str
,
link
:
str
|
None
=
None
)
->
None
:
def
log_error
(
msg
:
str
)
->
None
:
"""
Log helper.
"""
"""
Log helper.
"""
_LOGGER
.
error
(
"
Setup failed for %s: %s
"
,
domain
,
msg
)
if
integration
is
None
:
custom
=
""
link
=
None
else
:
custom
=
""
if
integration
.
is_built_in
else
"
custom integration
"
link
=
integration
.
documentation
_LOGGER
.
error
(
"
Setup failed for %s%s: %s
"
,
custom
,
domain
,
msg
)
async_notify_setup_error
(
hass
,
domain
,
link
)
async_notify_setup_error
(
hass
,
domain
,
link
)
try
:
try
:
...
@@ -174,7 +181,7 @@ async def _async_setup_component(
...
@@ -174,7 +181,7 @@ async def _async_setup_component(
try
:
try
:
await
async_process_deps_reqs
(
hass
,
config
,
integration
)
await
async_process_deps_reqs
(
hass
,
config
,
integration
)
except
HomeAssistantError
as
err
:
except
HomeAssistantError
as
err
:
log_error
(
str
(
err
)
,
integration
.
documentation
)
log_error
(
str
(
err
))
return
False
return
False
# Some integrations fail on import because they call functions incorrectly.
# Some integrations fail on import because they call functions incorrectly.
...
@@ -182,7 +189,7 @@ async def _async_setup_component(
...
@@ -182,7 +189,7 @@ async def _async_setup_component(
try
:
try
:
component
=
integration
.
get_component
()
component
=
integration
.
get_component
()
except
ImportError
as
err
:
except
ImportError
as
err
:
log_error
(
f
"
Unable to import component:
{
err
}
"
,
integration
.
documentation
)
log_error
(
f
"
Unable to import component:
{
err
}
"
)
return
False
return
False
processed_config
=
await
conf_util
.
async_process_component_config
(
processed_config
=
await
conf_util
.
async_process_component_config
(
...
@@ -190,7 +197,7 @@ async def _async_setup_component(
...
@@ -190,7 +197,7 @@ async def _async_setup_component(
)
)
if
processed_config
is
None
:
if
processed_config
is
None
:
log_error
(
"
Invalid config.
"
,
integration
.
documentation
)
log_error
(
"
Invalid config.
"
)
return
False
return
False
start
=
timer
()
start
=
timer
()
...
@@ -287,6 +294,7 @@ async def async_prepare_setup_platform(
...
@@ -287,6 +294,7 @@ async def async_prepare_setup_platform(
def
log_error
(
msg
:
str
)
->
None
:
def
log_error
(
msg
:
str
)
->
None
:
"""
Log helper.
"""
"""
Log helper.
"""
_LOGGER
.
error
(
"
Unable to prepare setup for platform %s: %s
"
,
platform_path
,
msg
)
_LOGGER
.
error
(
"
Unable to prepare setup for platform %s: %s
"
,
platform_path
,
msg
)
async_notify_setup_error
(
hass
,
platform_path
)
async_notify_setup_error
(
hass
,
platform_path
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_setup.py
+
17
−
0
View file @
e7ca6b6e
...
@@ -11,6 +11,7 @@ import voluptuous as vol
...
@@ -11,6 +11,7 @@ import voluptuous as vol
from
homeassistant
import
config_entries
,
setup
from
homeassistant
import
config_entries
,
setup
from
homeassistant.const
import
EVENT_COMPONENT_LOADED
,
EVENT_HOMEASSISTANT_START
from
homeassistant.const
import
EVENT_COMPONENT_LOADED
,
EVENT_HOMEASSISTANT_START
from
homeassistant.core
import
callback
from
homeassistant.core
import
callback
from
homeassistant.exceptions
import
HomeAssistantError
from
homeassistant.helpers
import
discovery
from
homeassistant.helpers
import
discovery
from
homeassistant.helpers.config_validation
import
(
from
homeassistant.helpers.config_validation
import
(
PLATFORM_SCHEMA
,
PLATFORM_SCHEMA
,
...
@@ -621,6 +622,22 @@ async def test_integration_disabled(hass, caplog):
...
@@ -621,6 +622,22 @@ async def test_integration_disabled(hass, caplog):
assert
disabled_reason
in
caplog
.
text
assert
disabled_reason
in
caplog
.
text
async
def
test_integration_logs_is_custom
(
hass
,
caplog
):
"""
Test we highlight it
'
s a custom component when errors happen.
"""
mock_integration
(
hass
,
MockModule
(
"
test_component1
"
),
built_in
=
False
,
)
with
patch
(
"
homeassistant.setup.async_process_deps_reqs
"
,
side_effect
=
HomeAssistantError
(
"
Boom
"
),
):
result
=
await
setup
.
async_setup_component
(
hass
,
"
test_component1
"
,
{})
assert
not
result
assert
"
Setup failed for custom integration test_component1: Boom
"
in
caplog
.
text
async
def
test_async_get_loaded_integrations
(
hass
):
async
def
test_async_get_loaded_integrations
(
hass
):
"""
Test we can enumerate loaded integations.
"""
"""
Test we can enumerate loaded integations.
"""
hass
.
config
.
components
.
add
(
"
notbase
"
)
hass
.
config
.
components
.
add
(
"
notbase
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment