Skip to content
Open
Changes from all commits
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
13 changes: 9 additions & 4 deletions py3status/parse_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from importlib import util
from pathlib import Path
from string import Template
from subprocess import CalledProcessError, check_output
from subprocess import CalledProcessError, TimeoutExpired, check_output

from py3status.constants import (
CONFIG_FILE_SPECIAL_SECTIONS,
Expand Down Expand Up @@ -689,13 +689,18 @@ def parse_config_error(e, config_path):

# get the file encoding this is important with multi-byte unicode chars
try:
encoding = check_output(["file", "-b", "--mime-encoding", "--dereference", config_path])
encoding = check_output(
["file", "-b", "--mime-encoding", "--dereference", config_path],
timeout=3,
)
encoding = encoding.strip().decode("utf-8")
except FileNotFoundError:
# can be missing on NixOS (see #1961)
notify_user("the 'file' command is missing, please install it.")
encoding = "utf-8"
except CalledProcessError:
except (CalledProcessError, TimeoutExpired):
# timeout can occur on some architectures where the magic
# database takes too long to load.
# bsd does not have the --mime-encoding so assume utf-8
encoding = "utf-8"
try:
Expand All @@ -704,7 +709,7 @@ def parse_config_error(e, config_path):
config_info = parse_config(f)
except ParseException as e:
config_info = parse_config_error(e, config_path)
except LookupError:
except (LookupError, UnicodeDecodeError):
with config_path.open() as f:
try:
config_info = parse_config(f)
Expand Down