# mapErrors

### CancellableTaskValidation.mapErrors

Namespace: `FsToolkit.ErrorHandling`

Function Signature:

```fsharp
('errorInput list -> 'errorOutput list)
  -> CancellableTaskValidation<'ok, 'errorInput>
  -> CancellableTaskValidation<'ok, 'errorOutput>
```

Applies a mapping function to the **entire error list** inside a `CancellableTaskValidation`. If the computation is `Ok`, the mapping function is not called and the value is propagated unchanged.

Note: `mapErrors` operates on the whole list at once. To map over individual errors, use [`mapError`](/fstoolkit-errorhandling/fstoolkit.errorhandling.icedtasks/index-1/maperror.md).

### Examples

#### Example 1

Deduplicating errors before returning them:

```fsharp
let validateInput (input: FormInput) : CancellableTaskValidation<ValidatedForm, string> =
    runValidation input
    |> CancellableTaskValidation.mapErrors List.distinct
```

#### Example 2

Sorting and limiting the number of errors returned to a caller:

```fsharp
let validateOrder (order: Order) : CancellableTaskValidation<ValidatedOrder, string> =
    runOrderValidation order
    |> CancellableTaskValidation.mapErrors (fun errs -> errs |> List.sort |> List.truncate 5)
```

#### Example 3

Converting a list of typed errors to a list of user-facing messages:

```fsharp
let processRequest (req: Request) : CancellableTaskValidation<Response, string> =
    validateRequest req
    |> CancellableTaskValidation.mapErrors (List.map (fun (e: DomainError) -> e.UserMessage))
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling.icedtasks/index-1/maperrors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
