# Function: safe()

> 

> **safe**\<`TData`, `TErrorShape`\>(`promise`): `Promise`\<[`SafeResult`](https://trpc.io/docs/typedoc/client/index/type-aliases/SafeResult.md)\<`TData`, `TErrorShape`\>\>

Defined in: [packages/client/src/safe.ts:47](https://github.com/trpc/trpc/blob/7c907acfd8b31929214792e3b8c2ad7a8ac72563/packages/client/src/safe.ts#L47)

Awaits a client `.query()` or `.mutate()` call without throwing, and
returns a `[data, error]` pair typed with the procedure's error shape.

## Type Parameters

| Type Parameter |
| ------ |
| `TData` |
| `TErrorShape` |

## Parameters

| Parameter | Type |
| ------ | ------ |
| `promise` | [`TRPCPromise`](https://trpc.io/docs/typedoc/client/index/type-aliases/TRPCPromise.md)\<`TData`, `TErrorShape`\> |

## Returns

`Promise`\<[`SafeResult`](https://trpc.io/docs/typedoc/client/index/type-aliases/SafeResult.md)\<`TData`, `TErrorShape`\>\>

## Example

```ts
const [post, error] = await safe(client.post.byId.query({ id }));
if (error) {
  console.error(error);
}

const id = post.id;
```

## See

https://trpc.io/docs/client/vanilla/error-handling#errors-as-values-with-safe
