mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Handle ValueError
This commit is contained in:
parent
8a0ee762a6
commit
5ea6858781
@ -15,10 +15,10 @@ DEFAULT_SOFT_FILE_LIMIT: Final = 2048
|
||||
|
||||
def set_open_file_descriptor_limit() -> None:
|
||||
"""Set the maximum open file descriptor soft limit."""
|
||||
# Check environment variable first, then use default
|
||||
soft_limit = int(os.environ.get("SOFT_FILE_LIMIT", DEFAULT_SOFT_FILE_LIMIT))
|
||||
|
||||
try:
|
||||
# Check environment variable first, then use default
|
||||
soft_limit = int(os.environ.get("SOFT_FILE_LIMIT", DEFAULT_SOFT_FILE_LIMIT))
|
||||
|
||||
# Get current limits
|
||||
current_soft, current_hard = resource.getrlimit(resource.RLIMIT_NOFILE)
|
||||
|
||||
@ -61,3 +61,5 @@ def set_open_file_descriptor_limit() -> None:
|
||||
|
||||
except OSError as err:
|
||||
_LOGGER.error("Failed to set file descriptor limit: %s", err)
|
||||
except ValueError as err:
|
||||
_LOGGER.error("Invalid file descriptor limit value: %s", err)
|
||||
|
@ -90,3 +90,18 @@ def test_set_open_file_descriptor_limit_os_error() -> None:
|
||||
assert (
|
||||
"Failed to set file descriptor limit" in mock_logger.error.call_args[0][0]
|
||||
)
|
||||
|
||||
|
||||
def test_set_open_file_descriptor_limit_value_error() -> None:
|
||||
"""Test handling ValueError when setting file limit."""
|
||||
|
||||
with (
|
||||
patch.dict(os.environ, {"SOFT_FILE_LIMIT": "invalid_value"}),
|
||||
patch("homeassistant.util.resource._LOGGER") as mock_logger,
|
||||
):
|
||||
set_open_file_descriptor_limit()
|
||||
|
||||
mock_logger.error.assert_called_once()
|
||||
assert (
|
||||
"Invalid file descriptor limit value" in mock_logger.error.call_args[0][0]
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user