Strapi Data Transfer: Error Handling, Exit Messaging & Failure Recovery#
The @strapi/data-transfer package (packages/core/data-transfer) implements strapi transfer, strapi import, and strapi export. Error handling is layered: the engine classifies failures, the destination provider rolls back database state, and the CLI emits a colored exit message before calling process.exit. A known DoS vulnerability in the JSONL parsing dependency (stream-json@1.9.1) is tracked under GHSA-528h-pc64-c93x.
Architecture Overview#
CLI action (transfer/import/export)
āā TransferEngine.transfer()
āā integrityCheck() ā version & schema validation
āā #transferStage() Ć 5 (entities, links, assets, schemas, configuration)
ā āā Node stream pipeline (source ā transforms ā destination)
āā destinationProvider.rollback() ā on any uncaught error
The five transfer stages are defined in the engine . Each stage's data is stored in the archive as JSONL files inside named directories (entities/, links/, schemas/, configuration/) .
Error Class Hierarchy#
All errors extend DataTransferError<T>. Two branches:
Engine errors (engine/errors.ts):
TransferEngineInitializationErrorā fatal, step =initializationTransferEngineValidationErrorā fatal, step =validation; thrown for version/schema mismatchesTransferEngineTransferErrorā fatal, step =transfer
Provider errors (errors/providers.ts):
ProviderInitializationErrorā fatal; e.g., missing encryption key, unreadable archiveProviderValidationErrorā severitysilly(non-fatal); e.g., asset preflight failuresProviderTransferErrorā fatal; thrown by restore write-streams on record-level failures
The severity field controls how reportError records diagnostics in the engine.
Engine-Level Error Handling#
Key file: packages/core/data-transfer/src/engine/index.ts
transfer() top-level catch #
On any failure: emits transfer::error on the progress stream ā calls reportError (deduplicating already-recorded instances) ā calls destinationProvider.rollback?.() ā re-throws to the CLI.
#transferStage per-stage catch #
On stage pipeline failure: records endTime, emits stage::error (triggers CLI red ā spinner), calls reportError, calls destination.destroy(e), re-throws.
panic(error) and abortTransfer() #
panicāreportError(error, 'fatal')+ immediate throw. Used for unrecoverable errors during bootstrap, close, and schema diff resolution.abortTransfer()ā sets#aborted = true, cancels the active pipeline viaAbortController, throws a fatalTransferEngineError. Any subsequent stage short-circuits immediately .
attemptResolveError middleware #
For ProviderTransferError instances with a recognized ErrorCode, registered error-handler middleware can set context.ignore = true ā suppressing the error and allowing the transfer to continue. Both the schema diff handler and the assets backup handler use this mechanism.
CLI-Level Exit Messaging#
Key file: packages/core/strapi/src/cli/commands/transfer/action.ts
| Helper | Behavior |
|---|---|
exitWith(code, message) | Logs green (code 0) or red (code ā 0), calls process.exit(code) |
exitMessageText(process, error?) | Returns "Transfer process has been completed successfully!" or "Transfer process failed." |
On success the action calls exitWith(0, exitMessageText('transfer')); on failure exitWith(1, exitMessageText('transfer', true)) (after sending telemetry). The same pattern applies to import and export CLI actions.
Signal handling#
Before engine.transfer(), setSignalHandler replaces SIGINT/SIGTERM/SIGQUIT with a handler that calls abortTransfer({ engine, strapi }) ā engine.abortTransfer() + strapi.destroy(). During interactive prompts the handler is extended to also call exitWith(1, ...), ensuring clean exit if Inquirer is active.
Progress spinner events#
The CLI subscribes to the engine's progress stream :
stage::errorāupdateLoader(stage, data).fail()ā red ā for the failing stagetransfer::errorāfinishStartingSpinner('fail')+ clear interval ā handles pre-stage failures (bootstrap, integrity check)
Failure Recovery Handlers#
getDiffHandler ā schema diff confirmation#
Registered via engine.onSchemaDiff(...). When schema diffs are detected:
- Reports per-diff warnings to engine diagnostics.
- Panics immediately if Review Workflows diffs are
modified. - Prompts the user (auto-confirmed with
--force). On confirmation, merges diffs intocontext.ignoredDiffs; otherwiseengine.panic()is reached.
getAssetsBackupHandler ā backup failure recovery#
Registered via engine.addErrorHandler('ASSETS_DIRECTORY_ERR', ...). When the assets backup directory cannot be created:
- Warns about write permissions on
public/. - Prompts whether to continue without backing up
public/uploads. - Sets
context.ignore = trueon confirmation soattemptResolveErrorsuppresses the error.
Destination Provider Rollback#
Key file: local-destination/index.ts
beforeTransfer() runs asset backup and full DB deletion inside a single transaction. rollback() calls transaction.rollback() which emits a rollback event on the transaction's internal EventEmitter, aborting the underlying DB transaction. The engine calls this automatically .
createTransaction wraps strapi.db.transaction as an event-driven callback queue: callbacks attach via spawn, execute serially inside one open DB transaction; rollback aborts, close commits.
JSONL Pipeline and stream-json Vulnerability#
The file source provider reads all data stages via #streamJsonlDirectory ā it builds a stream-chain that pipes each tar entry through stream-json/jsonl/Parser :
tar entry ā parser({ checkErrors: true }) ā (line) => line.value ā PassThrough
Parse errors are caught and forwarded as ProviderTransferError to destroy the output stream .
Vulnerability: stream-json@1.9.1 is pinned in @strapi/data-transfer . This version is affected by GHSA-528h-pc64-c93x (CVE-2026-71429): path filter operations (pick, ignore, filter, replace) exhibit O(depth²) complexity on deeply nested JSON, allowing a small crafted payload (~360 KB) to block the Node.js event loop for seconds to minutes. The fix, available in 3.5.0, caps nesting depth at 1024 by default and throws RangeError if exceeded.
An open Dependabot PR (#27556) upgrades stream-json from 1.9.1 to 3.5.0 in packages/core/data-transfer/package.json. No application code changes are included ā only the dependency version bumps.
Note: The JSONL import pipeline does not use stream-json path filters (
pick/ignore/filter/replace), so the DoS vector only applies if those filters are invoked directly. However, the upgrade is still recommended to close the exposure.
Key Entry Points#
| Concern | File |
|---|---|
| CLI transfer exit flow | cli/commands/transfer/action.ts |
exitWith / exitMessageText | cli/utils/helpers.ts#L85-103, cli/utils/data-transfer.ts#L24-34 |
| Engine error lifecycle | data-transfer/src/engine/index.ts |
| Error class definitions | engine/errors.ts, errors/providers.ts |
| Schema diff handler | cli/utils/data-transfer.ts (getDiffHandler) |
| Assets backup error handler | cli/utils/data-transfer.ts (getAssetsBackupHandler) |
| Signal handling / abort | cli/utils/data-transfer.ts (setSignalHandler, abortTransfer) |
| Local destination rollback | local-destination/index.ts#L166-197 |
| Transaction utility | data-transfer/src/utils/transaction.ts |
| File source provider (JSONL pipeline) | file/providers/source/index.ts |
| Dependabot stream-json upgrade PR | #27556 |