Skip to content

Commit

Permalink
Merge pull request #419 from muellerzr/exception
Browse files Browse the repository at this point in the history
Custom raise message helper
  • Loading branch information
jph00 authored Jun 16, 2022
2 parents 4f8e825 + d604ccc commit 4a5a643
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 148 deletions.
1 change: 1 addition & 0 deletions fastcore/_nbdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"utc2local": "03_xtras.ipynb",
"local2utc": "03_xtras.ipynb",
"trace": "03_xtras.ipynb",
"modify_exception": "03_xtras.ipynb",
"round_multiple": "03_xtras.ipynb",
"modified_env": "03_xtras.ipynb",
"ContextManagers": "03_xtras.ipynb",
Expand Down
21 changes: 19 additions & 2 deletions fastcore/xtras.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/03_xtras.ipynb (unless otherwise specified).


from __future__ import annotations


__all__ = ['dict2obj', 'obj2dict', 'repr_dict', 'is_listy', 'shufflish', 'mapped', 'IterLen', 'ReindexCollection',
'walk', 'globtastic', 'maybe_open', 'image_size', 'bunzip', 'join_path_file', 'loads', 'loads_multi',
'untar_dir', 'repo_details', 'run', 'open_file', 'save_pickle', 'load_pickle', 'get_source_link', 'truncstr',
'spark_chars', 'sparkline', 'autostart', 'EventTimer', 'stringfmt_names', 'PartialFormatter',
'partial_format', 'utc2local', 'local2utc', 'trace', 'round_multiple', 'modified_env', 'ContextManagers',
'str2bool']
'partial_format', 'utc2local', 'local2utc', 'trace', 'modify_exception', 'round_multiple', 'modified_env',
'ContextManagers', 'str2bool']

# Cell
#nbdev_comment from __future__ import annotations

# Cell
from .imports import *
Expand Down Expand Up @@ -467,6 +474,16 @@ def _inner(*args,**kwargs):
_inner._traced = True
return _inner

# Cell
def modify_exception(
e:Exception, # An exception
msg:str=None, # A custom message
replace:bool=False, # Whether to replace e.args with [msg]
) -> Exception:
"Modifies `e` with a custom message attached"
e.args = [f'{e.args[0]} {msg}'] if not replace and len(e.args) > 0 else [msg]
return e

# Cell
def round_multiple(x, mult, round_down=False):
"Round `x` to nearest multiple of `mult`"
Expand Down
Loading

0 comments on commit 4a5a643

Please sign in to comment.