From 65dd1f6d3ea488ccf433282b4caeacdd3e96b378 Mon Sep 17 00:00:00 2001 From: Samuel Maddock Date: Wed, 8 Jan 2025 17:13:20 -0500 Subject: [PATCH] fix: allow optional JsFrame.lineno --- crates/symbolicator-js/src/interface.rs | 3 ++- crates/symbolicator-js/src/symbolication.rs | 25 +++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/crates/symbolicator-js/src/interface.rs b/crates/symbolicator-js/src/interface.rs index d62511bf9..48a1e68d9 100644 --- a/crates/symbolicator-js/src/interface.rs +++ b/crates/symbolicator-js/src/interface.rs @@ -232,7 +232,8 @@ pub struct JsFrame { #[serde(skip_serializing_if = "Option::is_none")] pub abs_path: Option, - pub lineno: u32, + #[serde(skip_serializing_if = "Option::is_none")] + pub lineno: Option, #[serde(skip_serializing_if = "Option::is_none")] pub colno: Option, diff --git a/crates/symbolicator-js/src/symbolication.rs b/crates/symbolicator-js/src/symbolication.rs index 32c9bb325..37249c0a3 100644 --- a/crates/symbolicator-js/src/symbolication.rs +++ b/crates/symbolicator-js/src/symbolication.rs @@ -105,13 +105,20 @@ async fn symbolicate_js_frame( // we check for a valid line (i.e. >= 1) first, as we want to avoid resolving / scraping the minified // file in that case. we frequently saw 0 line/col values in combination with non-js files, // and we want to avoid scraping a bunch of html files in that case. - let line = if raw_frame.lineno > 0 { - raw_frame.lineno - } else { - return Err(JsModuleErrorKind::InvalidLocation { - line: raw_frame.lineno, - col: raw_frame.colno, - }); + let line = match raw_frame.lineno { + Some(lineno) if lineno > 0 => lineno, + Some(lineno) => { + return Err(JsModuleErrorKind::InvalidLocation { + line: lineno, + col: raw_frame.colno, + }); + } + None => { + return Err(JsModuleErrorKind::InvalidLocation { + line: 0, + col: raw_frame.colno, + }); + } }; let col = raw_frame.colno.unwrap_or_default(); @@ -255,7 +262,7 @@ async fn symbolicate_js_frame( frame.filename = Some(filename); } - frame.lineno = token.line().saturating_add(1); + frame.lineno = Some(token.line().saturating_add(1)); frame.colno = Some(token.column().saturating_add(1)); if !should_apply_source_context { @@ -309,7 +316,7 @@ async fn symbolicate_js_frame( } fn apply_source_context(frame: &mut JsFrame, source: &str) -> Result<(), JsModuleErrorKind> { - let lineno = frame.lineno as usize; + let lineno = frame.lineno.map(|line| line as usize).unwrap_or_default(); let column = frame.colno.map(|col| col as usize).unwrap_or_default(); if let Some((pre_context, context_line, post_context)) =