Skip to content

Commit

Permalink
fix(import): Stop Errors being swallowed for monster import
Browse files Browse the repository at this point in the history
closes #431
  • Loading branch information
symposion committed Mar 28, 2017
1 parent 5c8e36a commit 4f7dfda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
17 changes: 8 additions & 9 deletions lib/modules/monster-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,14 @@ module.exports = class MonsterManager extends ShapedModule {
return monsters
.reduce((prevPromise, monsterData) =>
prevPromise.then(() => {
const msg = this.reporter.getMessageStreamer(`${monsterData.name} Import`);
const character = _.reduce(characterRetrievalStrategies,
(result, strategy) => result || strategy(monsterData.name, errors), null);

if (!character) {
this.logger.error('Failed to find or create character for monster $$$', monsterData.name);
const errorText = `Error creating character: <ul><li>${errors.join('</li><li>')}</li></ul>`;
msg.finish(errorText);
return null;
}

Expand All @@ -292,7 +295,7 @@ module.exports = class MonsterManager extends ShapedModule {
character.set('name', monsterData.name);

return characterProcessors.reduce((charPromise, proc) =>
charPromise.then(updatedChar => proc(updatedChar, monsterData))
charPromise.then(updatedChar => proc(updatedChar, monsterData, msg))
, Promise.resolve(character))
.then((finishedChar) => {
importedList.push(finishedChar);
Expand All @@ -307,15 +310,11 @@ module.exports = class MonsterManager extends ShapedModule {
});
}

monsterDataPopulator(character, monsterData) {
const converted = this.srdConverter.convertMonster(monsterData);
this.logger.debug('Converted monster data: $$$', converted);
return this.importData(character, converted);
}
monsterDataPopulator(character, monsterData, msg) {
this.logger.debug('Importing new character data $$$', monsterData);
const data = this.srdConverter.convertMonster(monsterData);
this.logger.debug('Converted monster data: $$$', data);

importData(character, data) {
this.logger.debug('Importing new character data $$$', data);
const msg = this.reporter.getMessageStreamer(`${character.get('name')} Import`);
let charPromise = Promise.resolve(character);
if (!this.roll20.getAttrByName(character.id, 'version')) {
charPromise = this.importer.runImportStage(character, { sheet_opened: 1 }, 'Creating character', msg);
Expand Down
9 changes: 8 additions & 1 deletion test/dummy-reporter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

const _ = require('underscore');

class Reporter {
constructor() {
Expand All @@ -19,6 +19,13 @@ class Reporter {
setPlayer() {
}

getMessageStreamer() {
return {
stream: _.noop,
finish: _.noop,
};
}

// noinspection JSUnusedGlobalSymbols
reportError(message) {
this.errors.push(message);
Expand Down

0 comments on commit 4f7dfda

Please sign in to comment.