> For the complete documentation index, see [llms.txt](https://docs.adiom.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.adiom.io/enterprise/running-dsynct/data-transformations/troubleshooting.md).

# Troubleshooting Transforms

{% hint style="warning" %}
**Under construction.** This page describes the current behavior and is being extended. Reporting of failed documents (counts per error and the failed documents themselves) is being improved, and the details below may change.
{% endhint %}

A sync with a transform can lose or reject a document in two places:

* **Transform failure.** The transformer cannot apply the config to a document. Typical causes are a field that is missing or has an unexpected type in some documents.
* **Write failure.** The transform succeeded, but the destination rejected the result. Typical causes are a missing or invalid ID, a duplicate key, or a document that violates a destination limit or schema.

## What Happens When a Document Fails

The behavior depends on two settings: `filtererrors` in the transform config, and the `--ignore-write-failures` option of the worker or `sync` command.

| Setting                   | Transform failure                                                                                                                                                                            | Write failure                                                                                                                                                            |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Neither (default)         | The sync stops making progress on that task.                                                                                                                                                 | The sync stops making progress on that task.                                                                                                                             |
| `filtererrors: true`      | The failing document is skipped and logged. Other documents continue.                                                                                                                        | Not affected.                                                                                                                                                            |
| `--ignore-write-failures` | The whole batch that contains the failing document is skipped. The sync engine logs nothing; the transformer still logs one `filter-error` line for the first failing document of the batch. | The whole batch is skipped. The sync engine logs nothing; some connectors (MongoDB, PostgreSQL, Cosmos DB) log the write error themselves, without the IDs of the batch. |
| Both                      | The failing document is skipped and logged.                                                                                                                                                  | The whole batch is skipped.                                                                                                                                              |

"Stops making progress" means:

* **With Temporal:** the failing activity is retried without limit. The sync does not end, but that namespace partition or change stream does not advance. The error appears under **Last Activity Errors** in the [Progress](https://docs.adiom.io/enterprise/running-dsynct/web-api.md#progress) view. With `--pause-on-error`, the activity is paused instead of retried.
* **In simple mode (`sync`):** the sync ends in the `Error` state with the error message.

{% hint style="info" %}
`--ignore-write-failures` on its own also hides transform failures from the sync (only the transformer's log line for the first failing document of a batch remains), and it skips whole batches. To find out which documents fail to transform, always combine it with `filtererrors: true`. Use both for survey runs only. For the real migration, leave both off so that a failure cannot go unnoticed.
{% endhint %}

## Where to Look

| What you want to know                              | Where                                                                                                                                                                                                                                                                                        |
| -------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Which document failed to transform, and why        | The `filter-error` lines in the log of the process that runs the transformer (the worker, or the `sync` process).                                                                                                                                                                            |
| How many documents fail to transform               | The transformer's own counters, by `namespace` and `type` (`data` or `update`): `transform.conversion_error` counts documents skipped by `filtererrors: true`, `transform.filtered` counts documents dropped by `filter`, and `transform.in` and `transform.out` count documents in and out. |
| That transforms are failing without `filtererrors` | The `dsynct.get_transform` metric with `success=false`, by `namespace`. It counts failed batches, not documents.                                                                                                                                                                             |
| That writes are failing                            | The `dsynct.write_data` (initial sync) and `dsynct.write_updates` (CDC) metrics with `success=false`, and `dsynct.written` with `success=false` for the number of documents in failed batches.                                                                                               |
| The error that is blocking a Temporal sync         | **Last Activity Errors** in the Progress view.                                                                                                                                                                                                                                               |
| The error that ended a simple sync                 | The **Sync Error** block in the Progress view, the sync list, and the log line `Simple sync exited with error`.                                                                                                                                                                              |
| How many documents are missing                     | Compare document counts per namespace between source and destination, then use [verification](https://docs.adiom.io/enterprise/running-dsynct/verification.md).                                                                                                                              |

Metrics require OpenTelemetry to be enabled. The `dsynct.*` metrics are on the `dsync-flow` meter and the `transform.*` counters on the `dsync-transform` meter. See [Observability](https://docs.adiom.io/enterprise/running-dsynct/observability.md).

### The filter-error Log Line

Every document that fails to transform produces one line:

```
ERROR filter-error err="err in apply operations: err in qty: type conversion error from 'string' to 'int'" id=1 cfg=shop.orders
```

| Part  | Meaning                                                                                                                                             |
| ----- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| Level | `ERROR` when the failure stops the task. `WARN` when `filtererrors: true` skipped the document.                                                     |
| `err` | The stage that failed, the field (`err in qty`), and the reason.                                                                                    |
| `id`  | The source ID of the document.                                                                                                                      |
| `cfg` | The `namespace` of the mapping that was applied. With `defaultmapping`, this is the name of the default mapping, not the namespace of the document. |

The document itself is not logged. Use the ID to fetch it from the source, add it to your samples, and reproduce the error in [Transform Studio](https://docs.adiom.io/enterprise/running-dsynct/web-api.md#transform-studio).

The stage at the start of `err` tells you which part of the config failed:

| Stage                                     | Part of the config                                |
| ----------------------------------------- | ------------------------------------------------- |
| `err in apply operations: err in <field>` | The `cel` or `map` entry for `<field>`.           |
| `err in filter`                           | The `filter` expression.                          |
| `err in map id`                           | The `mapid` expression.                           |
| `err in marshall id`                      | The result of `mapid` does not fit `finalidkeys`. |

## Common Errors

### At Startup

These stop the worker or `sync` command before any data is read. In Transform Studio they appear as `invalid transformer config`.

| Message contains                         | Cause                                                                                                                                     | Fix                                                                                                                                                                                                                                                                |
| ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `no compatible data path`                | The source and destination have no data type in common and no transform was given.                                                        | Add a transform. See [When You Need a Transform](https://docs.adiom.io/enterprise/running-dsynct/data-transformations.md#when-you-need-a-transform).                                                                                                               |
| `no compatible data path with transform` | The transform was given, but it cannot connect these two connectors.                                                                      | Check that the source and destination are the right way round.                                                                                                                                                                                                     |
| `undeclared reference to '...'`          | A function or variable name in a CEL expression does not exist.                                                                           | Check the name in the [Config Reference](https://docs.adiom.io/enterprise/running-dsynct/data-transformations/config-reference.md#available-functions) and [CEL Reference](https://docs.adiom.io/enterprise/running-dsynct/data-transformations/cel-reference.md). |
| `found no matching overload for '...'`   | A function is called with argument types it does not accept.                                                                              | Convert the argument first, for example with `string()` or `int()`.                                                                                                                                                                                                |
| `filter should be a bool type`           | The `filter` expression is not a boolean at load time. The check is static, so `filter: env.flag` fails even when the value is a boolean. | Compare explicitly, for example `env.flag == true`.                                                                                                                                                                                                                |
| `self should be a map/document`          | The `self` expression is not a map at load time. `self: self` and `self: doc` are rejected for this reason.                               | Return a map literal, or `optional.of(self)`.                                                                                                                                                                                                                      |

### While Transforming

| Message contains                                                                   | Cause                                                                                                                                                                | Fix                                                                                                                                                                                                                          |
| ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `no such key: <name>`                                                              | The expression reads a field that this document does not have.                                                                                                       | Guard with `has(doc.<name>)`, or return `optional.none()`. See [Add or Remove a Field Conditionally](https://docs.adiom.io/enterprise/running-dsynct/data-transformations/templates.md#add-or-remove-a-field-conditionally). |
| `no such overload`                                                                 | An operator or function got a value of an unexpected type. Common with numbers from a JSON source, and with fields that hold different types in different documents. | Convert first: `int(self)`, `double(self)`, `string(self)`. See [Values as CEL Sees Them](https://docs.adiom.io/enterprise/running-dsynct/data-transformations/data-types.md#values-as-cel-sees-them).                       |
| `type conversion error from 'string' to 'int'`                                     | The value cannot be converted, for example `"abc"` to a number.                                                                                                      | Decide what such documents should become, and handle the case in the expression.                                                                                                                                             |
| `invalid UTF-8 in bytes, cannot convert to string`                                 | `string()` was applied to a binary value, usually an ObjectID.                                                                                                       | Use `bson_object_id_string()` for ObjectIDs. For other binary values use `base64.encode(self.Data)`, or `base64.encode(self)` with `unwrapbson: true`.                                                                       |
| `the provided hex string is not a valid ObjectID`                                  | `bson_object_id` got a string that is not 24 hexadecimal characters.                                                                                                 | Only use it on real ObjectID strings. For other IDs, keep the string, or derive an ObjectID with a hash.                                                                                                                     |
| `timestamp overflow`                                                               | `timestamp()` got milliseconds. It expects seconds, or an RFC 3339 string.                                                                                           | Divide by 1000.                                                                                                                                                                                                              |
| `type conversion is expected but no mapping found for namespace <ns>`              | The source and destination data types differ, and no mapping matches this namespace.                                                                                 | Add a mapping for the namespace, or a `defaultmapping`. Namespaces must match exactly. If you use `--namespace-mapping`, the transform receives the mapped namespace.                                                        |
| `id key length does not match id`                                                  | `mapid` returns a different number of parts than `finalidkeys` lists.                                                                                                | Make them the same length.                                                                                                                                                                                                   |
| `err id from data: positioned on invalid, but attempted to read embedded document` | A BSON document has no ID field named by `idkeys` (default `_id`). For a JSON source a missing ID field is not an error; `id` is null instead.                       | Set `idkeys` to the fields the source uses. This error is not skipped by `filtererrors`.                                                                                                                                     |

### No Error, but Wrong Data

| Symptom                                                                       | Likely cause                                                                                                                       |
| ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| A mapping has no effect                                                       | A misspelled option, or an unknown name under `map`. Both are ignored without an error. Or the `namespace` does not match exactly. |
| A field listed in `add` does not appear                                       | There is no `cel` entry for it, or its parent object does not exist.                                                               |
| Updates create a second document                                              | `mapid` and the `cel` entry for the ID field produce different values or types.                                                    |
| Deleted documents stay on the destination                                     | Same cause: the ID of the delete does not match the stored ID. Compare the `Data` and `Delete` results in Transform Studio.        |
| A numeric ID is a string after the initial sync, but a number after an update | A numeric ID from a JSON source. Use `int(id)` in both `mapid` and `cel`.                                                          |
| Integers are stored as 64-bit                                                 | Integers that pass through `cel` are 64-bit. Add `map: int32` for the field.                                                       |
| Dates are stored as strings                                                   | JSON has no date type. Convert with `timestamp(self)`.                                                                             |
| Fewer documents than expected, no errors                                      | `filter`, a `self` expression returning `optional.none()`, or a survey run with `--ignore-write-failures`.                         |

## Finding the Affected Documents

1. Collect the `filter-error` lines. Group them by `cfg` and by the text of `err` to see how many kinds of problems there are and how many documents each affects.
2. For each kind, fetch one or two of the listed IDs from the source and run them in Transform Studio.
3. For write failures, there is no per-document log. Compare counts per namespace, then use `sample-ids` and `verify-ids` with the transform to find examples of missing documents. See [Verification](https://docs.adiom.io/enterprise/running-dsynct/verification.md).
4. After fixing the config, re-run the affected namespaces.

## Known Gaps

These are current limitations of the tooling, not of your config:

* Test Sync and `testsync` do not report documents that failed to transform or write, and they still finish successfully. Check the destination.
* Failed documents are counted per namespace (`transform.conversion_error`) but not per error message, and they are not saved. Group the `filter-error` log lines by error text to count per error.
* When write failures are ignored, the IDs of the skipped documents are not logged.
* The Progress view does not show failure counts.
