From e6b883572808f0d7d0b166ddceb2812202d6788e Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Tue, 15 Nov 2022 15:23:32 +0100 Subject: [PATCH] chore(chalice): enhanced sourcemaps to handle incorrect frames --- api/chalicelib/core/sourcemaps.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api/chalicelib/core/sourcemaps.py b/api/chalicelib/core/sourcemaps.py index 886198e35..921649d97 100644 --- a/api/chalicelib/core/sourcemaps.py +++ b/api/chalicelib/core/sourcemaps.py @@ -54,7 +54,8 @@ def __frame_is_valid(f): def __format_frame(f): f["context"] = [] # no context by default - if "source" in f: f.pop("source") + if "source" in f: + f.pop("source") url = f.pop("fileName") f["absPath"] = url f["filename"] = urlparse(url).path @@ -74,8 +75,13 @@ def format_payload(p, truncate_to_first=False): def url_exists(url): - r = requests.head(url, allow_redirects=False) - return r.status_code == 200 and r.headers.get("Content-Type") != "text/html" + try: + r = requests.head(url, allow_redirects=False) + return r.status_code == 200 and r.headers.get("Content-Type") != "text/html" + except Exception as e: + print(f"!! Issue checking if URL exists: {url}") + print(e) + return False def get_traces_group(project_id, payload): @@ -97,8 +103,8 @@ def get_traces_group(project_id, payload): continue if key not in payloads: - file_exists_in_bucket = s3.exists(config('sourcemaps_bucket'), key) - if not file_exists_in_bucket: + file_exists_in_bucket = len(file_url) > 0 and s3.exists(config('sourcemaps_bucket'), key) + if len(file_url) > 0 and not file_exists_in_bucket: print(f"{u['absPath']} sourcemap (key '{key}') doesn't exist in S3 looking in server") if not file_url.endswith(".map"): file_url += '.map'