{"record":{"id":"4c2ba9a2cecf3ff6","repo":"napi-rs/napi-rs","slug":"invalid-release-name","errorCode":null,"errorMessage":"Invalid release name","messagePattern":"Invalid release name","errorType":"error_code","errorClass":"napi::Error (Status::StringExpected)","httpStatus":null,"severity":"error","filePath":"crates/napi/src/version.rs","lineNumber":23,"sourceCode":"pub struct NodeVersion {\n  pub major: u32,\n  pub minor: u32,\n  pub patch: u32,\n  pub release: &'static str,\n}\n\nimpl TryFrom<sys::napi_node_version> for NodeVersion {\n  type Error = Error;\n\n  fn try_from(value: sys::napi_node_version) -> Result<NodeVersion, Error> {\n    Ok(NodeVersion {\n      major: value.major,\n      minor: value.minor,\n      patch: value.patch,\n      release: unsafe {\n        CStr::from_ptr(value.release)\n          .to_str()\n          .map_err(|_| Error::new(Status::StringExpected, \"Invalid release name\".to_owned()))?\n      },\n    })\n  }\n}\n","sourceCodeStart":5,"sourceCodeEnd":28,"githubUrl":"https://github.com/napi-rs/napi-rs/blob/39bd1205e480a453a2da2601a760bde5a71ed016/crates/napi/src/version.rs#L5-L28","documentation":"When converting the raw `napi_node_version` struct into the safe `NodeVersion`, the `release` C string pointer (e.g. \"v20.11.0\") is not valid UTF-8, so `CStr::from_ptr(...).to_str()` fails and napi-rs returns `Status::StringExpected` with this message. This indicates corrupted or non-UTF-8 data in the underlying Node version info.","triggerScenarios":"Calling `napi_get_node_version` (exposed as `process.version`-style APIs in napi-rs) on a Node build whose `release` string contains invalid UTF-8 bytes, or a hostile/custom N-API shim returning a malformed release pointer.","commonSituations":"Custom/embedded Node builds or Electron forks with patched version strings; fuzzing or mocking the N-API layer with garbage pointers; extremely unusual locale-encoded build metadata.","solutions":["Run against a standard Node.js release; verify `process.release.name` is a normal UTF-8 string.","If using a custom Node/Electron build, check the build script that sets the release version string and ensure it is UTF-8.","If you control the call, handle the `Result` and fall back to a default version string instead of propagating the error.","Report/inspect the N-API shim if running under a non-Node runtime that implements `napi_get_node_version` incorrectly."],"exampleFix":"// before\nlet version = env.node_version()?;\n\n// after\nlet version = env.node_version().unwrap_or(NodeVersion {\n  major: 0, minor: 0, patch: 0,\n  release: \"unknown\".to_owned(),\n});","handlingStrategy":"try-catch","validationCode":"// Sanity-check the runtime before reading version info\nif (typeof process === 'undefined' || typeof process.release?.name !== 'string') {\n  throw new Error('Running under a runtime that may not provide a valid napi_get_node_version');\n}","typeGuard":"function isValidNodeVersion(v) {\n  return v != null && typeof v.release === 'string' && v.release.length > 0;\n}","tryCatchPattern":"let version;\ntry {\n  version = env.node_version()?;\n} catch (e) {\n  if (e.status === generic_failure && e.message === 'Invalid release name') {\n    version = fallbackVersion(); // or log and degrade\n  } else {\n    return Err(e);\n  }\n}","preventionTips":["Only run against standard Node.js releases; validate custom/Electron builds' `process.release.name`.","Degrade gracefully: treat node_version() as optional metadata and provide a fallback.","If embedding, ensure your N-API implementation returns a valid NUL-terminated UTF-8 release string."],"tags":["utf-8","string","node-version","ffi"],"backgroundTag":"invalid-utf8-string","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"}