# Accumulate independent errors before writing output

> For agents: start with the [agent guide](https://ratstack.sh/llms.txt). Every page is Markdown by default; add `Accept: text/html` for HTML.

New on /news: [Foldkit 0.171.0 requires result Message schemas](/news).

Error accumulation means reporting independent failures together before continuing with output.
[Effect](/lore/effect-basics) 4's [`Effect.validate`](https://github.com/Effect-TS/effect/blob/289a53f7b1fc40049219c6e69022db2fb859c356/packages/effect/src/Effect.ts#L612-L619) evaluates every collection element.
It returns all failures as a non-empty array when any element fails.
Successful values are discarded in that case.

## Worked example: collect snippet failures

The [code-snippets pipeline](/lore/code-snippets) applies this operation to Markdown code blocks.
Each job carries its parsed document node and source path.
`prepareCode` parses each request before rendering configured code.
A parse failure ends that job; validation continues across the other jobs.

The collection starts here:

packages/code-snippets/src/pipeline.ts at 4cd7cbbdb90386426f44643f6fc5b8e6c6e4286a; lines 303-312; highlighted none. Title: Validate each fence job.

```typescript
export const prepareCode = Effect.fn("prepareCode")(function* prepareCode(
  jobs: readonly FenceJob[]
) {
  const snippets = new Map<string, CodeSnippet>();
  const renderCache = new Map<string, CodeSnippet>();
  const diagnostics: Diagnostics[] = [];
  yield* Effect.validate(jobs, ({ node, sourcePath }) =>
    Effect.gen(function* validateFence() {
      const request = yield* parseCodeRequest(node, sourcePath);
      const highlighter = yield* Highlighter;
```

The `Effect.mapError` after `Effect.validate` turns collected failures into one `CodeBuildFailed` error.
It retains the individual failures and formats each one as a message with [diagnostic context](/lore/errors-are-part-of-the-interface).

packages/code-snippets/src/pipeline.ts at 4cd7cbbdb90386426f44643f6fc5b8e6c6e4286a; lines 359-369; highlighted none. Title: Keep each failure in the build error.

```typescript
  ).pipe(
    Effect.mapError(
      (errors: readonly CodeError[]) =>
        new CodeBuildFailed({
          failures: errors,
          messages: errors.map(formatCodeError),
        })
    )
  );

  return { diagnostics, snippets };
```

The site generator follows this order:

1. Collect and verify code blocks.
2. Run `prepareCode` over the jobs.
3. Report diagnostics and construct the Code component from prepared snippets.

## Check the failure path

The P7 [property test](https://github.com/joelhooks/rat-stack/blob/4cd7cbbdb90386426f44643f6fc5b8e6c6e4286a/packages/code-snippets/test/pipeline.test.ts#L413-L441) generates one to eight jobs with unknown repository names.
It expects one message and one `CodeUnknownRepo` failure per job.
The test increments a counter only in a success continuation after `prepareCode`.
For these invalid jobs, the counter stays zero.

This proves the continuation does not run; it does not observe filesystem asset writes.

Read [property-based testing](/lore/property-based-testing) for generated inputs, and the [snippet pipeline](/lore/code-snippets) for the full build path.

## Sources

1. [Effect.validate, Effect 4.1.4](https://github.com/Effect-TS/effect/blob/289a53f7b1fc40049219c6e69022db2fb859c356/packages/effect/src/Effect.ts#L612-L619)
   Effect contributors. Evaluates each element and accumulates typed failures. Successful values are discarded when validation fails. Accessed 2026-11-14.

2. [Snippet preparation and error accumulation](https://github.com/joelhooks/rat-stack/blob/4cd7cbbdb90386426f44643f6fc5b8e6c6e4286a/packages/code-snippets/src/pipeline.ts#L303-L369)
   rat-stack contributors. prepareCode validates fence jobs and maps collected errors into CodeBuildFailed. Accessed 2026-11-14.

3. [P7 independent failures property](https://github.com/joelhooks/rat-stack/blob/4cd7cbbdb90386426f44643f6fc5b8e6c6e4286a/packages/code-snippets/test/pipeline.test.ts#L413-L441)
   rat-stack contributors. Generated invalid jobs produce one message per failure and skip the success continuation. Accessed 2026-11-14.

4. [Prepare snippets before constructing the Code component](https://github.com/joelhooks/rat-stack/blob/4cd7cbbdb90386426f44643f6fc5b8e6c6e4286a/apps/site/scripts/generate-content.ts#L994-L1003)
   rat-stack contributors. The generator verifies fences, prepares snippets, and reports diagnostics before constructing the component. Accessed 2026-11-14.

## Linked from

- Agent guide → An Effect stack so pure (aspirational) Kit Langton will blush. → [Read page](https://ratstack.sh/llms.txt)

- Build-time work stays out of requests → Git reads and highlighting produce static assets before the Worker handles requests. → [Read page](https://ratstack.sh/lore/build-time-work-stays-out-of-requests)

- Change log → What changed in the files served here, newest first. → [Read page](https://ratstack.sh/log)

- Code snippets quote a pinned source → Shipped design brief: pinned Git objects, typed diagnostics, and one build-only snippet model for both views. → [Read page](https://ratstack.sh/lore/code-snippets)

- Durability starts with a recovery record → A reading order for storage, replay, worker ownership, overload, and recovery tests. → [Read page](https://ratstack.sh/lore/durability)

- Errors are part of the interface → An author error needs a location, the rejected input, and a repair. → [Read page](https://ratstack.sh/lore/errors-are-part-of-the-interface)

- Full agent guide → An Effect stack so pure (aspirational) Kit Langton will blush. → [Read page](https://ratstack.sh/llms-full.txt)

- Handle expected failures without hiding defects → Declare expected failures, preserve their context, and recover by tag without turning crashes into successful outcomes. → [Read page](https://ratstack.sh/lore/error-model)

- Rat Stack lore | rat-stack → Short, source-grounded notes on the ideas and decisions behind rat-stack. → [Read page](https://ratstack.sh/lore)

- Source change history (log.md) → The generated change log as Markdown. → [Read page](https://ratstack.sh/log.md)
