{"record":{"id":"9daf5f2c21b2dcbc","repo":"napi-rs/napi-rs","slug":"format-msg","errorCode":null,"errorMessage":"format!($($msg)*)","messagePattern":"format!\\(\\$\\(\\$msg\\)\\*\\)","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"info","filePath":"crates/napi/src/error.rs","lineNumber":1721,"sourceCode":"        // value came back as a plain `Error` (its fallback is\n        // `JsError::into_value`).\n        Ok(unsafe { val.into_value(env) })\n      }\n    }\n  };\n}\n\nimpl_object_methods!(JsError, sys::napi_create_error);\nimpl_object_methods!(JsTypeError, sys::napi_create_type_error);\nimpl_object_methods!(JsRangeError, sys::napi_create_range_error);\n#[cfg(feature = \"napi9\")]\nimpl_object_methods!(JsSyntaxError, sys::node_api_create_syntax_error);\n\n#[doc(hidden)]\n#[macro_export]\nmacro_rules! error {\n  ($status:expr, $($msg:tt)*) => {\n    $crate::Error::new($status, format!($($msg)*))\n  };\n}\n\n#[doc(hidden)]\n#[macro_export]\nmacro_rules! check_status {\n  ($code:expr) => {{\n    let c = $code;\n    match c {\n      $crate::sys::Status::napi_ok => Ok(()),\n      _ => Err($crate::Error::new($crate::Status::from(c), \"\".to_owned())),\n    }\n  }};\n\n  ($code:expr, $($msg:tt)*) => {{\n    let c = $code;\n    match c {\n      $crate::sys::Status::napi_ok => Ok(()),","sourceCodeStart":1703,"sourceCodeEnd":1739,"githubUrl":"https://github.com/napi-rs/napi-rs/blob/39bd1205e480a453a2da2601a760bde5a71ed016/crates/napi/src/error.rs#L1703-L1739","documentation":"The `error!` macro expands to `Error::new($status, format!($($msg)*))`, constructing a library error with a formatted message and a caller-chosen `Status`. Any error you see created via `error!(...)` in napi-rs or user code takes its message from the format arguments here.","triggerScenarios":"Any use of `napi::error!(status, \"...\")` in `#[napi]` code — e.g. `error!(Status::InvalidArg, \"expected {} elements\", n)` — including inside the crate's own code paths.","commonSituations":"Custom validation in native functions that returns formatted errors; users searching JS stack traces for these messages should look for the matching `error!` invocation in Rust.","solutions":["Locate the `error!` call producing your exact message to find the failing validation","Fix the input/condition described by the formatted message","Choose a more specific `Status` than GenericFailure where applicable"],"exampleFix":"// before\nreturn Err(error!(Status::GenericFailure, \"bad input\"));\n// after\nreturn Err(error!(Status::InvalidArg, \"expected number, got {}\", ty));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { nativeFn(args); } catch (e) {\n  if (e.code === 'GenericFailure' || e.code === 'InvalidArg') { /* message came from error! formatting; handle per validation */ }\n  else throw e;\n}","preventionTips":["Use `error!` with specific Status values (InvalidArg, etc.) rather than GenericFailure","Keep formatted messages stable — JS callers may pattern-match them","Grep Rust sources for the exact message text to locate the throwing validation"],"tags":["napi-rs","macro","error-construction"],"backgroundTag":"invalid-argument","analyzedSha":"39bd1205e480a453a2da2601a760bde5a71ed016","analyzedAt":"2026-09-13T20:31:47.814Z","contentChangedAt":"2026-09-13T20:31:47.814Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}