Function: inspectError()

Executes a side effect function on the error value of a Result or ResultAsync, without modifying the original result. This is useful for debugging, logging, or performing other side effects while maintaining the original value and error state.

Type Param

The input Result or ResultAsync.

Type Param

The return type of the inspection function.

Examples

import { Result } from '@praha/byethrow';

const result = Result.pipe(
  Result.fail('error'),
  Result.inspectError((error) => console.log('Debug error:', error)),
);
// Console output: "Debug error: error"
// Result: { type: 'Failure', error: 'error' }
import { Result } from '@praha/byethrow';

const result = Result.pipe(
  Result.succeed(42),
  Result.inspectError((error) => console.log('Debug error:', error)),
);
// No console output
// Result: { type: 'Success', value: 42 }

See

pipe - It is recommended to use this function with the pipe function for better readability and composability.

Call Signature

inspectError<R1>(fn): (result) => R1

Defined in: functions/inspect-error.ts:46

Type Parameters

R1

R1 extends ResultMaybeAsync<any, any>

Parameters

fn

(a) => unknown

Returns

(result): R1

Parameters

result

R1

Returns

R1

Call Signature

inspectError<F>(fn): <R1>(result) => R1

Defined in: functions/inspect-error.ts:47

Type Parameters

F

F extends (a) => unknown

Parameters

fn

F

Returns

<R1>(result): R1

Type Parameters

R1

R1 extends ResultMaybeAsync<any, Parameters<F>[0]>

Parameters

result

R1

Returns

R1