---
editLink: false
lastUpdated: false
---

[@salesforce/b2c-tooling-sdk](../../modules.md) / [cli](../index.md) / serializeErrorCause

# Function: serializeErrorCause()

> **serializeErrorCause**(`cause`): `unknown`

Defined in: [packages/b2c-tooling-sdk/src/cli/base-command.ts:163](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/8fc17d8708d025c83fb0c44ca73198a200605153/packages/b2c-tooling-sdk/src/cli/base-command.ts#L163)

Render an error's `cause` for the `--json` error envelope. A plain `String()`
turns the common case — an object `cause` such as a parsed SCAPI error body —
into the useless `"[object Object]"`. Preserve structure instead: expose an
`Error` cause as `{name, message}` and a plain object/array cause as itself
(the outer `JSON.stringify` serializes it), falling back to `String()` only
for primitives.

## Parameters

### cause

`unknown`

## Returns

`unknown`
