Skip to main content

lindera_nodejs/
error.rs

1//! Error handling utilities for Lindera Node.js bindings.
2//!
3//! Provides helper functions to convert Rust errors into napi-rs errors
4//! that are thrown as JavaScript exceptions.
5
6use std::fmt::Display;
7
8use napi::Status;
9
10/// Converts any displayable error into a napi error.
11///
12/// # Arguments
13///
14/// * `err` - Any error type that implements `Display`.
15///
16/// # Returns
17///
18/// A `napi::Error` with `GenericFailure` status and the error message.
19pub fn to_napi_error(err: impl Display) -> napi::Error {
20    napi::Error::new(Status::GenericFailure, format!("{err}"))
21}