option-t
Version:
A toolkit of Nullable/Option/Result type implementation in ECMAScript. Their APIs are inspired by Rust's `Option<T>` and `Result<T, E>`.
19 lines (18 loc) • 642 B
JavaScript
import { isCurrentRealmErrorInstance } from '../../internal/assert.js';
import { ERR_MSG_DOT_CAUSE_PROPS_IS_NOT_CURRENT_REALM_BUILTIN_ERROR_INSTANCE } from './error_message.js';
const WRAPPER_NAME = 'UnknownCausalError';
export class UnknownCausalError extends Error {
constructor(cause) {
super(ERR_MSG_DOT_CAUSE_PROPS_IS_NOT_CURRENT_REALM_BUILTIN_ERROR_INSTANCE, {
cause,
});
this.name = WRAPPER_NAME;
}
}
export function wrapWithNewErrorIfCausalIsUnknown(e) {
if (isCurrentRealmErrorInstance(e)) {
return e;
}
const wrapper = new UnknownCausalError(e);
return wrapper;
}