Skip to content

Commit

Permalink
Fix error code check in windows (vercel#73981)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaojude authored Dec 16, 2024
1 parent ac89400 commit 0f288c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/next-error-code-swc-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct NewError {
}

fn is_error_class_name(name: &str) -> bool {
// Error classes are collected by https://gist.github.com/eps1lon/6cce3059dfa061f2a7dc28305fdaddae#file-collect-error-constructors-mjs
name == "AggregateError"
// built-in error classes
|| name == "Error"
Expand Down Expand Up @@ -150,9 +151,13 @@ impl VisitMut for TransformVisitor {
}

let new_error_expr: NewExpr = new_error_expr.unwrap();
let error_message = error_message.unwrap();

// Normalize line endings by converting Windows CRLF (\r\n) to Unix LF (\n)
// This ensures the comparison works consistently across different operating systems
let error_message = error_message.unwrap().replace("\r\n", "\n");

let code = self.errors.iter().find_map(|(key, value)| {
// We assume `errors.json` uses Unix LF (\n) as line endings
if *value == error_message {
Some(key)
} else {
Expand Down
Binary file modified packages/next/next_error_code_swc_plugin.wasm
Binary file not shown.

0 comments on commit 0f288c4

Please sign in to comment.