Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

tryCatchIntoResultWithEnsureErrorAsync

  • This function converts the returend value from producer into Ok(T).
  • If producer throw a value that is an instance of Error of current realm, this returns it with wrapping Err(Error).
  • Otherwise, if producer throw a value that is not an instance of current realm including a one created from cross-ream Error constructor (e.g. node:vm, iframe), then this operator creates a new Error object created from the current realm's constructor and the thrown value to its Error.cause, make it Err(Error), and return it finally.

This just returns it directly if the thrown value is an Error instance of the current realm. We can do this due to that we can regard it is happen in the same operation step to throw a value unlike the combination of tryCatchIntoResult + mapErrForResult. This shortcut can reduce an unnecessary Error.cause chain.


NOTE:

  1. An user should narrow the scope of producer to make it predictable that is in Err(E).
  2. This function requires ES2022's Error.cause to get an actual thrown object.
  3. Basically, we don't recomment to use this to create a Result<T, E>. Generally, you should define an Err(E) by depending on an use case context Use this operator just to make a bridge to existing codebase that you cannot inspect deeply to details.
function tryCatchIntoResultWithEnsureErrorAsync<T>(producer: AsyncProducerFn<T>): Promise<Result<T, Error>>;
§
tryCatchIntoResultWithEnsureErrorAsync<T>(producer: AsyncProducerFn<T>): Promise<Result<T, Error>>
[src]

§Type Parameters

§Parameters

§
producer: AsyncProducerFn<T>
[src]

§Return Type

§
Promise<Result<T, Error>>
[src]