From c692790a9e8571de06c171cd2463835d2dde7d16 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Fri, 20 Jan 2023 11:41:55 +0100 Subject: [PATCH] feat(chalice): errors_helper --- api/chalicelib/utils/errors_helper.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 api/chalicelib/utils/errors_helper.py diff --git a/api/chalicelib/utils/errors_helper.py b/api/chalicelib/utils/errors_helper.py new file mode 100644 index 000000000..73a430110 --- /dev/null +++ b/api/chalicelib/utils/errors_helper.py @@ -0,0 +1,14 @@ +from chalicelib.core import sourcemaps + + +def format_first_stack_frame(error): + error["stack"] = sourcemaps.format_payload(error.pop("payload"), truncate_to_first=True) + for s in error["stack"]: + for c in s.get("context", []): + for sci, sc in enumerate(c): + if isinstance(sc, str) and len(sc) > 1000: + c[sci] = sc[:1000] + # convert bytes to string: + if isinstance(s["filename"], bytes): + s["filename"] = s["filename"].decode("utf-8") + return error