Skip to content

Commit

Permalink
tweak how errors are handled with custom data functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctalkington committed Jun 5, 2015
1 parent 1138d5f commit c0f3b86
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,15 @@ Archiver.prototype.bulk = function(mappings) {
}

try {
entryData = dataFunction(entryData) || entryData;
} catch(e) {}
entryData = dataFunction ? dataFunction(entryData) : entryData;

if (dataFunction && typeof entryData !== 'object') {
throw new Error('bulk: invalid data returned from custom function');
}
} catch(e) {
self.emit('error', e);
return;
}

self._append(filepath, entryData);
});
Expand Down Expand Up @@ -446,8 +453,15 @@ Archiver.prototype.directory = function(dirpath, destpath, data) {
entryData.stats = file.stats;

try {
entryData = dataFunction(entryData) || entryData;
} catch(e) {}
entryData = dataFunction ? dataFunction(entryData) : entryData;

if (dataFunction && typeof entryData !== 'object') {
throw new Error('directory: invalid data returned from custom function');
}
} catch(e) {
self.emit('error', e);
return;
}

self._append(file.path, entryData);
});
Expand Down

0 comments on commit c0f3b86

Please sign in to comment.