diff --git a/CHANGELOG.md b/CHANGELOG.md index 78a3afa..9bdd42a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * errors: expose CSV_INVALID_ARGUMENT * errors: expose CSV_INVALID_COLUMN_DEFINITION +* errors: expose CSV_OPTION_COLUMNS_MISSING_NAME * errors: expose CSV_INVALID_OPTION_BOM * errors: expose CSV_INVALID_OPTION_CAST * errors: expose CSV_INVALID_OPTION_CAST_DATE diff --git a/lib/es5/index.js b/lib/es5/index.js index 41c0498..fcf771b 100644 --- a/lib/es5/index.js +++ b/lib/es5/index.js @@ -1257,7 +1257,7 @@ var normalizeColumnsArray = function normalizeColumnsArray(columns) { }; } else if (isObject(column)) { if (typeof column.name !== 'string') { - throw new Error("Invalid Option columns: property \"name\" is required at position ".concat(i, " when column is an object literal")); + throw new CsvError('CSV_OPTION_COLUMNS_MISSING_NAME', ['Option columns missing name:', "property \"name\" is required at position ".concat(i), 'when column is an object literal']); } normalizedColumns[i] = column; diff --git a/lib/index.js b/lib/index.js index 1b7bf83..31a631f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1023,7 +1023,11 @@ const normalizeColumnsArray = function(columns){ normalizedColumns[i] = { name: column } }else if(isObject(column)){ if(typeof column.name !== 'string'){ - throw new Error(`Invalid Option columns: property "name" is required at position ${i} when column is an object literal`) + throw new CsvError('CSV_OPTION_COLUMNS_MISSING_NAME', [ + 'Option columns missing name:', + `property "name" is required at position ${i}`, + 'when column is an object literal' + ]) } normalizedColumns[i] = column }else{ diff --git a/test/option.columns.coffee b/test/option.columns.coffee index 0c5a80b..79957e9 100644 --- a/test/option.columns.coffee +++ b/test/option.columns.coffee @@ -13,7 +13,9 @@ describe 'Option `columns`', -> },{ invalid: 'oh no' }], (->) - ).should.throw 'Invalid Option columns: property "name" is required at position 1 when column is an object literal' + ).should.throw + message: 'Option columns missing name: property "name" is required at position 1 when column is an object literal' + code: 'CSV_OPTION_COLUMNS_MISSING_NAME' it 'check the columns value', -> (->