Skip to content

Commit

Permalink
Handle decode and interruption errors
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniosarosi committed Jan 31, 2021
1 parent b9fc359 commit 7b26278
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pycritty/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Automated tools for managing alacritty configurations"""

__version__ = "0.3.3"
__version__ = "0.3.4"


class PycrittyError(Exception):
Expand Down
12 changes: 7 additions & 5 deletions pycritty/io/yio.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def read_yaml(url: Union[str, Path, Resource]) -> Dict[str, Any]:
return yaml.load(f, Loader=yaml.FullLoader)
except (IOError, URLError) as e:
raise YamlIOError(f'Error trying to access "{url}":\n{e}')
except (UnicodeDecodeError, yaml.reader.ReaderError) as e:
raise YamlParseError(f'Failed decoding "{url}":\n{e}')
except yaml.YAMLError as e:
raise YamlParseError((
'YAML error at "{0}", '
'at line {1.problem_mark.line}, '
'column {1.problem_mark.column}:\n'
'{1.problem} {1.context}'
).format(url, e))
f'YAML error at "{url}", '
f'at line {e.problem_mark.line}, '
f'column {e.problem_mark.column}:\n'
f'{e.problem} {e.context or ""}'
))


def write_yaml(y: Dict[str, Any], file: Union[Path, Resource]):
Expand Down
4 changes: 3 additions & 1 deletion pycritty/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def main():
args.pop('subcommand')
try:
command_receiver().execute(args)
except PycrittyError as e:
except (PycrittyError, KeyboardInterrupt) as e:
if isinstance(e, KeyboardInterrupt):
e = 'Interrupted, changes might not have been applied'
log.err(e)
exit(1)

Expand Down

0 comments on commit 7b26278

Please sign in to comment.