alef 0.114.0

Opinionated polyglot binding generator for Rust libraries
Documentation
/// Convert a `{{ rust_path }}` error to a NAPI error.
///
/// The stable numeric error code is deliberately not interpolated into this message —
/// `napi::Error` has no per-variant subclass to attach it to. When available, it is exposed
/// as a structured `code` field on the `*Info` companion class instead (see
/// `gen_napi_error_class`), never smuggled into human-facing text. (~keep)
#[allow(dead_code)]
fn {{ fn_name }}(e: {{ rust_path }}) -> napi::Error {
    let mut error = napi::Error::new(napi::Status::GenericFailure, e.to_string());
    let (kind, error_code): (&str, u32) = match &e {
{% for pattern, name, code in arms %}
        {{ pattern }} => ("{{ name }}", {{ code }}),
{% endfor %}
        #[allow(unreachable_patterns)]
        _ => ("Unknown", {{ unknown_code }}),
    };
    let info = format!(
        "{{ json_template }}",
{% for expression in json_args %}
        {{ expression }}{{ "," if not loop.last else "" }}
{% endfor %}
    );
    error.set_cause(napi::Error::new(
        napi::Status::GenericFailure,
        format!("{{ marker }}{info}"),
    ));
    error
}