Skip to content

Commit a9be7d2

Browse files
author
Riccardo Busetti
authored
fix(sourcemaps): Add error when fetching is disabled (#46657)
1 parent ed96bb1 commit a9be7d2

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/sentry/lang/javascript/processor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,10 +1173,14 @@ def fetch_by_url(self, url):
11731173
cache_key = f"source:cache:v4:{md5_text(url).hexdigest()}"
11741174

11751175
if result is None:
1176-
if not self.allow_scraping or not url.startswith(("http:", "https:")):
1176+
if not url.startswith(("http:", "https:")):
11771177
error = {"type": EventError.JS_MISSING_SOURCE, "url": http.expose_url(url)}
11781178
raise http.CannotFetch(error)
11791179

1180+
if not self.allow_scraping:
1181+
error = {"type": EventError.JS_SCRAPING_DISABLED, "url": http.expose_url(url)}
1182+
raise http.CannotFetch(error)
1183+
11801184
logger.debug("Checking cache for url %r", url)
11811185
result = cache.get(cache_key)
11821186
if result is not None:

src/sentry/models/eventerror.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class EventError:
3535
JS_TOO_LARGE = "js_too_large" # deprecated in favor of FETCH_TOO_LARGE
3636
JS_FETCH_TIMEOUT = "js_fetch_timeout" # deprecated in favor of FETCH_TIMEOUT
3737
JS_MISSING_SOURCES_CONTENT = "js_missing_sources_content"
38+
JS_SCRAPING_DISABLED = "js_scraping_disabled"
3839

3940
# Processing: Native
4041
NATIVE_NO_CRASHED_THREAD = "native_no_crashed_thread"

tests/relay_integration/lang/javascript/test_plugin.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,42 @@ def test_html_file_with_query_param_ending_with_js_extension(self):
16311631

16321632
assert "errors" not in event.data
16331633

1634+
def test_expansion_with_allow_scraping_false(self):
1635+
project = self.project
1636+
project.organization.update_option("sentry:scrape_javascript", False)
1637+
1638+
data = {
1639+
"timestamp": self.min_ago,
1640+
"message": "hello",
1641+
"platform": "javascript",
1642+
"release": "1.0",
1643+
"exception": {
1644+
"values": [
1645+
{
1646+
"type": "Error",
1647+
"stacktrace": {
1648+
"frames": [
1649+
{
1650+
"abs_path": "http://example.com/file.min.js",
1651+
"filename": "file.min.js",
1652+
"lineno": 1,
1653+
"colno": 39,
1654+
},
1655+
]
1656+
},
1657+
}
1658+
]
1659+
},
1660+
}
1661+
1662+
event = self.post_and_retrieve_event(data)
1663+
1664+
assert len(event.data["errors"]) == 1
1665+
assert event.data["errors"][0] == {
1666+
"type": "js_scraping_disabled",
1667+
"url": "http://example.com/file.min.js",
1668+
}
1669+
16341670
def test_expansion_with_debug_id(self):
16351671
project = self.project
16361672
release = Release.objects.create(organization_id=project.organization_id, version="abc")

0 commit comments

Comments
 (0)