# Errors You Can Actually See in Effect (Learning Effect, Part 5)

- Published: 2026-07-14
- Updated: 2026-10-17
- Tags: Learning Effect, Effect, TypeScript
- URL: https://devtrillo.com/writing/learning-effect-5-errors-you-can-actually-see/

JavaScript lets any function throw almost anything.

A string. An `Error`. A random object. Something from a library you did not know was inside the call stack.

TypeScript does not show that in the function type.

Effect does.

## The plain version

```ts
try {
  const user = await getUser(input);
} catch (error) {
  // what is error?
}
```

With `strict` on, `error` is `unknown`.

TypeScript cannot know what was thrown, so it does not guess.

You check with `instanceof` and hope your list is complete.

Nothing tells you when a new error appears deeper in the stack.

That is the problem Effect is trying to fix.

## Give errors names

```ts
class InvalidUserId {
  readonly _tag = "InvalidUserId";
  constructor(readonly input: string) {}
}

class UserNotFound {
  readonly _tag = "UserNotFound";
  constructor(readonly id: number) {}
}
```

The `_tag` looks odd at first. It gives the error a stable name.

That makes it easy to handle one error later.

**Quiz:** Why add a _tag to Effect errors?

- So errors can be identified and handled by name
- So TypeScript makes them async
- So the program runs faster

**Answer:** So errors can be identified and handled by name — The tag gives each error a clear identity. Later, catchTag can use it.

## The type becomes honest

```ts
const program = parseUserId(input).pipe(Effect.flatMap(fetchUser));
```

The type can say:

```ts
Effect.Effect<User, InvalidUserId | UserNotFound, never>;
```

That is useful before you run anything.

You can see what the caller must care about.

**Quiz:** Which errors can this program fail with?

- Only UserNotFound
- InvalidUserId or UserNotFound
- No errors

**Answer:** InvalidUserId or UserNotFound — The error slot is a union of the errors from each step.

## The mistake: errors as strings

Strings are the fastest way to fail.

```ts
const program = Effect.fail("User not found");
```

The type is `Effect.Effect<never, string, never>`.

That compiles. It also tells the caller almost nothing.

Two different failures both look like `string`.

You cannot catch one by name.

A typo in the message changes nothing in the type.

Matching on message text is how the old `try/catch` code worked.

It breaks the day someone edits the wording.

`new Error("...")` has the same problem. Every failure becomes `Error`.

How to spot it: read the error slot. If it says `string` or `Error`, the names are missing.

Give each failure its own class with a `_tag`.

The `_tag` is what `catchTag` reads in the next part.

## This changes the conversation

Without Effect, I often ask:

> Does this throw?

With Effect, I ask:

> What does the error slot say?

That is a better question.

It moves failure from memory into the type.

> **Note:** I do not want clever errors. I want boring errors with names a tired person
> can understand.
