}
export const utils = { sleep };
+/**
+ * Create a `TransformationErrorFunction` that handles errors by silently swallowing the error and skipping the output
+ * row.
+ *
+ * @returns {TransformationErrorFunction} A `TransformationErrorFunction` that may be passed to a `CSVTransformer`'s
+ * `onError` option.
+ */
+function skip() {
+ return () => null;
+}
+
/**
* Create a `TransformationErrorFunction` that handles errors by filling the output row with a given placeholder value.
*
}
}
-export const ErrorStrategies = { placeholder, retry, backoff };
+export const ErrorStrategies = { skip, placeholder, retry, backoff };
Object.freeze(ErrorStrategies);
\ No newline at end of file
import { CSVTransformer } from '../src/core.js';
import { ErrorStrategies } from '../src/errorStrategies.js';
-const { placeholder, retry, backoff } = ErrorStrategies;
+const { skip, placeholder, retry, backoff } = ErrorStrategies;
/**
* Generate a function that will throw errors until it is called **exactly** `count` times.
return { min, max };
}
+suite('ErrorStrategies.skip', { concurrency: true }, () => {
+ test('skips errors', async () => {
+ await createCSVMockStream([
+ ['header', 'header', 'header'],
+ ['1', '1', '1'],
+ ['2', '2', '2'],
+ ['3', '3', '3']
+ ])
+ .pipeThrough(new CSVTransformer(r => { throw new Error(); }, { onError: skip() }))
+ .pipeTo(csvStreamEqualWritable([
+ ['header', 'header', 'header']
+ ]));
+ });
+});
+
suite('ErrorStrategies.placeholder', { concurrency: true }, () => {
test('sets placeholders on all fields in a row', async () => {
await createCSVMockStream([