const require_errors = require('./types/errors.cjs');
const require_context_impl = require('./context_impl.cjs');

//#region src/error_sanitization.ts
/**
* Strips SDK-internal metadata from an error before it enters the interceptor
* chain. Interceptors see a plain Error — no CommandError.
*/
function sanitizeError(e) {
	if (e instanceof require_context_impl.CommandError) return require_errors.ensureError(e.cause);
	return require_errors.ensureError(e);
}
/**
* Restores SDK-internal metadata after the interceptor chain exits, using the
* original error's metadata and the interceptor's error as the new cause.
* If the original had no SDK metadata, the interceptor's error passes through
* unchanged.
*/
function restoreError(interceptorError, original) {
	if (original instanceof require_context_impl.CommandError) return original.commandIndex !== void 0 ? new require_context_impl.CommandError(interceptorError, original.commandType, original.commandIndex) : new require_context_impl.CommandError(interceptorError, original.commandType);
	return interceptorError;
}

//#endregion
exports.restoreError = restoreError;
exports.sanitizeError = sanitizeError;