From 27eb427245b5126335cef0adb5e57522272474b5 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 13 Sep 2021 18:29:10 -0700 Subject: [PATCH] add stream_error function --- jc/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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