Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
errors: expose CSV_OPTION_COLUMNS_MISSING_NAME
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 1, 2019
1 parent a37dd48 commit b76d470
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/es5/index.js
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion lib/index.js
Expand Up @@ -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{
Expand Down
4 changes: 3 additions & 1 deletion test/option.columns.coffee
Expand Up @@ -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', ->
(->
Expand Down

0 comments on commit b76d470

Please sign in to comment.