[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Result](https://evolu.dev/docs/api-reference/common/Result) › trySync

```ts
function trySync<T, E>(
  fn: () => T,
  mapError: (error: unknown) => E,
): Result<T, E>;
```

Defined in: [packages/common/src/Result.ts:408](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Result.ts#L408)

Wraps a synchronous function that may throw, returning a [Result](https://evolu.dev/docs/api-reference/common/Result/type-aliases/Result).

Use this when the thrown value should become a typed, recoverable error for
the caller. Do not use it for failures that should terminate the current flow
and propagate to a global handler.

### Example

```ts
const parseJson = (value: string): Result<unknown, ParseJsonError> =>
  trySync(
    () => JSON.parse(value) as unknown,
    (error) => ({ type: "ParseJsonError", message: String(error) }),
  );
```