throw if napi function returns Err variant of Result<T>
This commit is contained in:
parent
ee7a146ea1
commit
f66f79e587
12 changed files with 53 additions and 37 deletions
examples/napi
|
@ -16,7 +16,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
export enum Kind { Dog = 0, Cat = 1, Duck = 2 }␊
|
||||
export enum CustomNumEnum { One = 1, Two = 2, Three = 3, Four = 4, Six = 6, Eight = 8, Nine = 9, Ten = 10 }␊
|
||||
export function enumToI32(e: CustomNumEnum): number␊
|
||||
export function getError(): Error | undefined␊
|
||||
export function throwError(): void␊
|
||||
export function mapOption(val: number | null): number | null␊
|
||||
export function add(a: number, b: number): number␊
|
||||
export function fibonacci(n: number): number␊
|
||||
|
|
Binary file not shown.
|
@ -19,7 +19,7 @@ import {
|
|||
createObj,
|
||||
mapOption,
|
||||
readFile,
|
||||
getError,
|
||||
throwError,
|
||||
} from '../'
|
||||
|
||||
test('number', (t) => {
|
||||
|
@ -98,7 +98,5 @@ test('Option', (t) => {
|
|||
})
|
||||
|
||||
test('Result', (t) => {
|
||||
const error = getError()
|
||||
t.not(error, undefined)
|
||||
t.is(error!.message, 'Manual Error')
|
||||
t.throws(() => throwError(), null, 'Manual Error')
|
||||
})
|
||||
|
|
2
examples/napi/index.d.ts
vendored
2
examples/napi/index.d.ts
vendored
|
@ -6,7 +6,7 @@ export function readFile(callback: (arg0: Error | undefined, arg1: string | null
|
|||
export enum Kind { Dog = 0, Cat = 1, Duck = 2 }
|
||||
export enum CustomNumEnum { One = 1, Two = 2, Three = 3, Four = 4, Six = 6, Eight = 8, Nine = 9, Ten = 10 }
|
||||
export function enumToI32(e: CustomNumEnum): number
|
||||
export function getError(): Error | undefined
|
||||
export function throwError(): void
|
||||
export function mapOption(val: number | null): number | null
|
||||
export function add(a: number, b: number): number
|
||||
export function fibonacci(n: number): number
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use napi::bindgen_prelude::*;
|
||||
|
||||
#[napi]
|
||||
fn get_error() -> Result<()> {
|
||||
fn throw_error() -> Result<()> {
|
||||
Err(Error::new(Status::InvalidArg, "Manual Error".to_owned()))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue