{"record":{"id":"0e2232adc9e6e71f","repo":"swc-project/swc","slug":"invalidarg","errorCode":"InvalidArg","errorMessage":"invalid `syntax`: {err}","messagePattern":"invalid `syntax`: (.+?)","errorType":"validation","errorClass":"napi::Error","httpStatus":null,"severity":"error","filePath":"bindings/binding_react_compiler_node/src/lint.rs","lineNumber":38,"sourceCode":"/// tests call constructs a `napi::Error` anywhere in its body — even in a\n/// branch that specific test never executes — the whole function's compiled\n/// object code references those unresolved symbols, and a standalone\n/// `cargo test` binary (never loaded by Node) fails to link. Keep this\n/// function's signature free of `napi::Error`/`napi::Result` so tests can\n/// call it safely.\nfn decode_syntax(bytes: &[u8]) -> std::result::Result<Syntax, serde_json::Error> {\n    serde_json::from_slice(bytes)\n}\n\n/// Thin napi-facing wrapper — not unit tested (see `decode_syntax`'s doc\n/// comment), matching this crate's existing convention of only testing the\n/// pure logic behind a `#[napi]` function, never the function itself (see\n/// `support.rs`'s `is_react_compiler_required(_sync)`, which have no tests\n/// at all).\nfn parse_syntax_option(syntax: Option<Buffer>) -> napi::Result<Syntax> {\n    match syntax {\n        Some(buf) => decode_syntax(buf.as_ref()).map_err(|err| {\n            napi::Error::new(napi::Status::InvalidArg, format!(\"invalid `syntax`: {err}\"))\n        }),\n        None => Ok(default_syntax()),\n    }\n}\n\nfn lint_inner(code: &str, syntax: Syntax) -> Vec<Diagnostic> {\n    let result = swc_ecma_react_compiler::lint_source(\n        code,\n        syntax,\n        swc_ecma_react_compiler::default_plugin_options(),\n    );\n\n    result\n        .diagnostics\n        .iter()\n        .map(|d| diagnostic_from_message(code, d))\n        .collect()\n}","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/bindings/binding_react_compiler_node/src/lint.rs#L20-L56","documentation":"parse_syntax_option deserializes the caller-supplied `syntax` option from JSON bytes into the parser's Syntax config; malformed JSON or an unknown shape makes serde_json fail and lint/lint_sync wrap the error before any parsing starts. The binding was called with an invalid option payload.","triggerScenarios":"Thrown at bindings/binding_react_compiler_node/src/lint.rs:38 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Send a JSON value matching the expected Syntax option shape","Log the wrapped serde_json error to find the offending field","Validate the option payload on the JS side before calling the binding"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}