File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -861,10 +861,14 @@ const transform = function (original_options = {}) {
861861 if ( skip_records_with_error ) {
862862 this . state . recordHasError = true ;
863863 if ( this . options . on_skip !== undefined ) {
864- this . options . on_skip (
865- err ,
866- raw ? this . state . rawBuffer . toString ( encoding ) : undefined ,
867- ) ;
864+ try {
865+ this . options . on_skip (
866+ err ,
867+ raw ? this . state . rawBuffer . toString ( encoding ) : undefined ,
868+ ) ;
869+ } catch ( err ) {
870+ return err ;
871+ }
868872 }
869873 // this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
870874 return undefined ;
Original file line number Diff line number Diff line change 11import "should" ;
2+ import dedent from "dedent" ;
23import { parse } from "../lib/index.js" ;
34import { assert_error } from "./api.assert_error.js" ;
45
@@ -10,6 +11,27 @@ describe("Option `on_skip`", function () {
1011 } ) . should . throw ( "Invalid Option: on_skip must be a function, got 1" ) ;
1112 } ) ;
1213
14+ it ( "catch thrown error" , function ( next ) {
15+ parse (
16+ dedent `
17+ a,b,c,d
18+ invalid
19+ e,f,g,h
20+ ` ,
21+ {
22+ bom : true ,
23+ skip_records_with_error : true ,
24+ on_skip : ( ) => {
25+ throw Error ( "Catchme" ) ;
26+ } ,
27+ } ,
28+ ( err ) => {
29+ err . message . should . eql ( "Catchme" ) ;
30+ next ( ) ;
31+ } ,
32+ ) ;
33+ } ) ;
34+
1335 it ( 'handle "CSV_RECORD_INCONSISTENT_FIELDS_LENGTH" with bom (fix #411)' , function ( next ) {
1436 let errors = 0 ;
1537 const parser = parse (
@@ -36,10 +58,13 @@ describe("Option `on_skip`", function () {
3658 next ( err ) ;
3759 } ,
3860 ) ;
39- parser . write ( `a,b,c,d
40- 1,2,3
41- e,f,g,h
42- ` ) ;
61+ parser . write (
62+ dedent `
63+ a,b,c,d
64+ 1,2,3
65+ e,f,g,h
66+ ` ,
67+ ) ;
4368 parser . end ( ) ;
4469 } ) ;
4570} ) ;
You can’t perform that action at this time.
0 commit comments