Skip to content

Commit 7b26278

Browse files
committed
Handle decode and interruption errors
1 parent b9fc359 commit 7b26278

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

pycritty/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Automated tools for managing alacritty configurations"""
22

3-
__version__ = "0.3.3"
3+
__version__ = "0.3.4"
44

55

66
class PycrittyError(Exception):

pycritty/io/yio.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ def read_yaml(url: Union[str, Path, Resource]) -> Dict[str, Any]:
4242
return yaml.load(f, Loader=yaml.FullLoader)
4343
except (IOError, URLError) as e:
4444
raise YamlIOError(f'Error trying to access "{url}":\n{e}')
45+
except (UnicodeDecodeError, yaml.reader.ReaderError) as e:
46+
raise YamlParseError(f'Failed decoding "{url}":\n{e}')
4547
except yaml.YAMLError as e:
4648
raise YamlParseError((
47-
'YAML error at "{0}", '
48-
'at line {1.problem_mark.line}, '
49-
'column {1.problem_mark.column}:\n'
50-
'{1.problem} {1.context}'
51-
).format(url, e))
49+
f'YAML error at "{url}", '
50+
f'at line {e.problem_mark.line}, '
51+
f'column {e.problem_mark.column}:\n'
52+
f'{e.problem} {e.context or ""}'
53+
))
5254

5355

5456
def write_yaml(y: Dict[str, Any], file: Union[Path, Resource]):

pycritty/main.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def main():
1717
args.pop('subcommand')
1818
try:
1919
command_receiver().execute(args)
20-
except PycrittyError as e:
20+
except (PycrittyError, KeyboardInterrupt) as e:
21+
if isinstance(e, KeyboardInterrupt):
22+
e = 'Interrupted, changes might not have been applied'
2123
log.err(e)
2224
exit(1)
2325

0 commit comments

Comments
 (0)