Skip to content

Commit

Permalink
fix(rests): Fix crash on undefined trait uses
Browse files Browse the repository at this point in the history
Traits marked to recharge with no defined 'uses' attribute will no longer cause the script to crash.
An error will now sent to the log in this case.
fixes: #81
  • Loading branch information
jaltepeter committed Apr 27, 2016
1 parent 3879fb5 commit 4b84523
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rest-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ class RestManager {
this.logger.debug(`Recharging '${attName}'`);
traitNames.push(attName);
const max = this.roll20.getAttrByName(charId, `${traitPre}_uses`, 'max');
this.roll20.setAttrByName(charId, `${traitPre}_uses`, max);
if (max === undefined) {
this.logger.error(`Tried to recharge the trait '${attName}' for character with id ${charId}, ` +
'but there were no uses defined.');
}
else {
this.roll20.setAttrByName(charId, `${traitPre}_uses`, max);
}
}
});

Expand Down

0 comments on commit 4b84523

Please sign in to comment.