Unverified Commit 409b7a6a authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Add support for Next.js error telemetry for `AggregateError` (#90391)

parent f74bdef4
...@@ -75,7 +75,7 @@ fn is_error_class_name(name: &str) -> bool { ...@@ -75,7 +75,7 @@ fn is_error_class_name(name: &str) -> bool {
|| name == "Warning" || name == "Warning"
} }
// Get the string representation of the first argument of `new Error(...)` // Get the string representation of the message argument of `new Error(...)`
fn stringify_new_error_arg(expr: &Expr, bindings: &FxHashMap<Id, String>) -> String { fn stringify_new_error_arg(expr: &Expr, bindings: &FxHashMap<Id, String>) -> String {
match expr { match expr {
Expr::Lit(lit) => match lit { Expr::Lit(lit) => match lit {
...@@ -136,10 +136,13 @@ impl VisitMut for TransformVisitor { ...@@ -136,10 +136,13 @@ impl VisitMut for TransformVisitor {
Expr::New(new_expr) => match &*new_expr.callee { Expr::New(new_expr) => match &*new_expr.callee {
Expr::Ident(ident) if is_error_class_name(ident.sym.as_str()) => { Expr::Ident(ident) if is_error_class_name(ident.sym.as_str()) => {
if let Some(args) = &new_expr.args { if let Some(args) = &new_expr.args {
if let Some(first_arg) = args.first() { // AggregateError(errors, message) has the message as the second arg
let message_arg_index =
if ident.sym.as_str() == "AggregateError" { 1 } else { 0 };
if let Some(message_arg) = args.get(message_arg_index) {
new_error_expr = Some(new_expr.clone()); new_error_expr = Some(new_expr.clone());
error_message = Some(stringify_new_error_arg( error_message = Some(stringify_new_error_arg(
&first_arg.expr, &message_arg.expr,
&self.resolved_bindings, &self.resolved_bindings,
)); ));
} }
...@@ -150,9 +153,12 @@ impl VisitMut for TransformVisitor { ...@@ -150,9 +153,12 @@ impl VisitMut for TransformVisitor {
Expr::Call(call_expr) => match &call_expr.callee { Expr::Call(call_expr) => match &call_expr.callee {
Callee::Expr(expr) => match &**expr { Callee::Expr(expr) => match &**expr {
Expr::Ident(ident) if is_error_class_name(ident.sym.as_str()) => { Expr::Ident(ident) if is_error_class_name(ident.sym.as_str()) => {
if let Some(first_arg) = call_expr.args.first() { // AggregateError(errors, message) has the message as the second arg
let message_arg_index =
if ident.sym.as_str() == "AggregateError" { 1 } else { 0 };
if let Some(message_arg) = call_expr.args.get(message_arg_index) {
error_message = Some(stringify_new_error_arg( error_message = Some(stringify_new_error_arg(
&first_arg.expr, &message_arg.expr,
&self.resolved_bindings, &self.resolved_bindings,
)); ));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment