diff --git a/jc/utils.py b/jc/utils.py index 3adfd69f..700b09e0 100644 --- a/jc/utils.py +++ b/jc/utils.py @@ -173,6 +173,22 @@ def convert_to_bool(value): return False +def stream_error(e, quiet, line): + """reraise the stream exception with annotation or print an error _meta field if quiet=True""" + if not quiet: + e.args = (str(e) + '... Use the quiet option (-q) to ignore errors.',) + raise e + else: + return { + '_meta': + { + 'success': False, + 'error': 'error parsing line', + 'line': line.strip() + } + } + + class timestamp: """ Input a date-time text string of several formats and convert to a naive or timezone-aware epoch timestamp in UTC