mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	sentry: Do not assume context lines exist in stacktrace.
`context_line` may not be set.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							56698d4a9a
						
					
				
				
					commit
					e637004695
				
			
							
								
								
									
										155
									
								
								zerver/webhooks/sentry/fixtures/event_for_exception_js.json
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										155
									
								
								zerver/webhooks/sentry/fixtures/event_for_exception_js.json
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,155 @@
 | 
			
		||||
{
 | 
			
		||||
    "action": "triggered",
 | 
			
		||||
    "data": {
 | 
			
		||||
        "event": {
 | 
			
		||||
            "event_id": "355c3b2a142046629dd410db2fdda003",
 | 
			
		||||
            "project": 5216640,
 | 
			
		||||
            "release": null,
 | 
			
		||||
            "dist": null,
 | 
			
		||||
            "platform": "javascript",
 | 
			
		||||
            "message": "",
 | 
			
		||||
            "datetime": "2020-06-17T14:42:54.656000Z",
 | 
			
		||||
            "tags": [
 | 
			
		||||
                ["browser", "Firefox 77.0"],
 | 
			
		||||
                ["browser.name", "Firefox"],
 | 
			
		||||
                ["handled", "yes"],
 | 
			
		||||
                ["level", "error"],
 | 
			
		||||
                ["mechanism", "generic"],
 | 
			
		||||
                ["os.name", "Ubuntu"],
 | 
			
		||||
                ["user", "ip:223.230.114.198"],
 | 
			
		||||
                [
 | 
			
		||||
                    "url",
 | 
			
		||||
                    "file:///mnt/data/Documents/Stuff%20for%20Zulip/Repos/sentry/js/trigger-exception-with-external.html"
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
            "_metrics": {
 | 
			
		||||
                "bytes.ingested.event": 876,
 | 
			
		||||
                "flag.processing.error": true,
 | 
			
		||||
                "bytes.stored.event": 2637
 | 
			
		||||
            },
 | 
			
		||||
            "contexts": {
 | 
			
		||||
                "os": {
 | 
			
		||||
                    "type": "os",
 | 
			
		||||
                    "name": "Ubuntu"
 | 
			
		||||
                },
 | 
			
		||||
                "browser": {
 | 
			
		||||
                    "version": "77.0",
 | 
			
		||||
                    "type": "browser",
 | 
			
		||||
                    "name": "Firefox"
 | 
			
		||||
                }
 | 
			
		||||
            },
 | 
			
		||||
            "culprit": "?(/mnt/data/Documents/Stuff%20for%20Zulip/Repos/sentry/js/external.js)",
 | 
			
		||||
            "errors": [
 | 
			
		||||
                {
 | 
			
		||||
                    "url": "file:///mnt/data/Documents/Stuff%20for%20Zulip/Repos/sentry/js/external.js",
 | 
			
		||||
                    "type": "js_no_source"
 | 
			
		||||
                }
 | 
			
		||||
            ],
 | 
			
		||||
            "exception": {
 | 
			
		||||
                "values": [
 | 
			
		||||
                    {
 | 
			
		||||
                        "stacktrace": {
 | 
			
		||||
                            "frames": [
 | 
			
		||||
                                {
 | 
			
		||||
                                    "abs_path": "file:///mnt/data/Documents/Stuff%20for%20Zulip/Repos/sentry/js/external.js",
 | 
			
		||||
                                    "filename": "/mnt/data/Documents/Stuff%20for%20Zulip/Repos/sentry/js/external.js",
 | 
			
		||||
                                    "colno": 25,
 | 
			
		||||
                                    "data": {
 | 
			
		||||
                                        "orig_in_app": 1
 | 
			
		||||
                                    },
 | 
			
		||||
                                    "lineno": 4
 | 
			
		||||
                                }
 | 
			
		||||
                            ]
 | 
			
		||||
                        },
 | 
			
		||||
                        "type": "Error",
 | 
			
		||||
                        "mechanism": {
 | 
			
		||||
                            "synthetic": null,
 | 
			
		||||
                            "help_link": null,
 | 
			
		||||
                            "type": "generic",
 | 
			
		||||
                            "meta": null,
 | 
			
		||||
                            "handled": true,
 | 
			
		||||
                            "data": null,
 | 
			
		||||
                            "description": null
 | 
			
		||||
                        },
 | 
			
		||||
                        "value": "Something external broke."
 | 
			
		||||
                    }
 | 
			
		||||
                ]
 | 
			
		||||
            },
 | 
			
		||||
            "fingerprint": ["{{ default }}"],
 | 
			
		||||
            "grouping_config": {
 | 
			
		||||
                "enhancements": "eJybzDhxY3J-bm5-npWRgaGlroGxrpHxBABcTQcY",
 | 
			
		||||
                "id": "newstyle:2019-10-29"
 | 
			
		||||
            },
 | 
			
		||||
            "hashes": ["2058ed8b75cb570c9646adcd9dc21843"],
 | 
			
		||||
            "key_id": "1146336",
 | 
			
		||||
            "level": "error",
 | 
			
		||||
            "location": null,
 | 
			
		||||
            "logger": "",
 | 
			
		||||
            "metadata": {
 | 
			
		||||
                "type": "Error",
 | 
			
		||||
                "filename": "/mnt/data/Documents/Stuff%20for%20Zulip/Repos/sentry/js/external.js",
 | 
			
		||||
                "value": "Something external broke."
 | 
			
		||||
            },
 | 
			
		||||
            "received": 1592406695.060435,
 | 
			
		||||
            "request": {
 | 
			
		||||
                "cookies": null,
 | 
			
		||||
                "url": "file:///mnt/data/Documents/Stuff%20for%20Zulip/Repos/sentry/js/trigger-exception-with-external.html",
 | 
			
		||||
                "headers": [
 | 
			
		||||
                    [
 | 
			
		||||
                        "User-Agent",
 | 
			
		||||
                        "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:77.0) Gecko/20100101 Firefox/77.0"
 | 
			
		||||
                    ]
 | 
			
		||||
                ],
 | 
			
		||||
                "env": null,
 | 
			
		||||
                "fragment": null,
 | 
			
		||||
                "query_string": [],
 | 
			
		||||
                "data": null,
 | 
			
		||||
                "method": null,
 | 
			
		||||
                "inferred_content_type": null
 | 
			
		||||
            },
 | 
			
		||||
            "sdk": {
 | 
			
		||||
                "version": "5.17.0",
 | 
			
		||||
                "name": "sentry.javascript.browser",
 | 
			
		||||
                "packages": [
 | 
			
		||||
                    {
 | 
			
		||||
                        "version": "5.17.0",
 | 
			
		||||
                        "name": "npm:@sentry/browser"
 | 
			
		||||
                    }
 | 
			
		||||
                ],
 | 
			
		||||
                "integrations": [
 | 
			
		||||
                    "InboundFilters",
 | 
			
		||||
                    "FunctionToString",
 | 
			
		||||
                    "TryCatch",
 | 
			
		||||
                    "Breadcrumbs",
 | 
			
		||||
                    "GlobalHandlers",
 | 
			
		||||
                    "LinkedErrors",
 | 
			
		||||
                    "UserAgent"
 | 
			
		||||
                ]
 | 
			
		||||
            },
 | 
			
		||||
            "timestamp": 1592404974.656,
 | 
			
		||||
            "title": "Error: Something external broke.",
 | 
			
		||||
            "type": "error",
 | 
			
		||||
            "user": {
 | 
			
		||||
                "geo": {
 | 
			
		||||
                    "city": "Hyderabad",
 | 
			
		||||
                    "region": "India",
 | 
			
		||||
                    "country_code": "IN"
 | 
			
		||||
                },
 | 
			
		||||
                "ip_address": "223.230.114.198"
 | 
			
		||||
            },
 | 
			
		||||
            "version": "7",
 | 
			
		||||
            "url": "https://sentry.io/api/0/projects/hypro999-personal-organization/zulip-integration-testing/events/355c3b2a142046629dd410db2fdda003/",
 | 
			
		||||
            "web_url": "https://sentry.io/organizations/hypro999-personal-organization/issues/1731239773/events/355c3b2a142046629dd410db2fdda003/",
 | 
			
		||||
            "issue_url": "https://sentry.io/api/0/issues/1731239773/"
 | 
			
		||||
        },
 | 
			
		||||
        "triggered_rule": "Send a webhook payload to Webhook.site"
 | 
			
		||||
    },
 | 
			
		||||
    "installation": {
 | 
			
		||||
        "uuid": "65027794-169a-4042-80d0-808ece377141"
 | 
			
		||||
    },
 | 
			
		||||
    "actor": {
 | 
			
		||||
        "type": "application",
 | 
			
		||||
        "id": "sentry",
 | 
			
		||||
        "name": "Sentry"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -118,6 +118,17 @@ Traceback:
 | 
			
		||||
            "webhook_event_for_exception_javascript", expected_topic, expected_message
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_event_for_exception_js(self) -> None:
 | 
			
		||||
        expected_topic = "Error: Something external broke."
 | 
			
		||||
        expected_message = """
 | 
			
		||||
**New exception:** [Error: Something external broke.](https://sentry.io/organizations/hypro999-personal-organization/issues/1731239773/events/355c3b2a142046629dd410db2fdda003/)
 | 
			
		||||
```quote
 | 
			
		||||
**level:** error
 | 
			
		||||
**timestamp:** 2020-06-17 14:42:54
 | 
			
		||||
**filename:** /mnt/data/Documents/Stuff%20for%20Zulip/Repos/sentry/js/external.js
 | 
			
		||||
```"""
 | 
			
		||||
        self.check_webhook("event_for_exception_js", expected_topic, expected_message)
 | 
			
		||||
 | 
			
		||||
    def test_event_for_message_golang(self) -> None:
 | 
			
		||||
        expected_topic = "A test message event from golang."
 | 
			
		||||
        expected_message = """
 | 
			
		||||
 
 | 
			
		||||
@@ -129,14 +129,14 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
 | 
			
		||||
                    exception_frame = frame
 | 
			
		||||
                    break
 | 
			
		||||
 | 
			
		||||
            if exception_frame and exception_frame["context_line"]:
 | 
			
		||||
                pre_context = convert_lines_to_traceback_string(exception_frame["pre_context"])
 | 
			
		||||
 | 
			
		||||
            if exception_frame and "context_line" in exception_frame:
 | 
			
		||||
                pre_context = convert_lines_to_traceback_string(
 | 
			
		||||
                    exception_frame.get("pre_context", None)
 | 
			
		||||
                )
 | 
			
		||||
                context_line = exception_frame["context_line"] + "\n"
 | 
			
		||||
                if not context_line:
 | 
			
		||||
                    context_line = "\n"  # nocoverage
 | 
			
		||||
 | 
			
		||||
                post_context = convert_lines_to_traceback_string(exception_frame["post_context"])
 | 
			
		||||
                post_context = convert_lines_to_traceback_string(
 | 
			
		||||
                    exception_frame.get("post_context", None)
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
                context.update(
 | 
			
		||||
                    syntax_highlight_as=syntax_highlight_as,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user