---
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:166](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/36eea0d308f1312d1a446ec8813ed30b0bdba62c/packages/b2c-tooling-sdk/src/cli/base-command.ts#L166)

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`
