import { ensureError } from "./types/errors.js";
import { CommandError } from "./context_impl.js";

//#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 CommandError) return ensureError(e.cause);
	return 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 CommandError) return original.commandIndex !== void 0 ? new CommandError(interceptorError, original.commandType, original.commandIndex) : new CommandError(interceptorError, original.commandType);
	return interceptorError;
}

//#endregion
export { restoreError, sanitizeError };
//# sourceMappingURL=error_sanitization.js.map