Skip to content

Commit

Permalink
fix(dicetray): error handling for roll button (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
twiescha authored Oct 26, 2023
1 parent bf87aa8 commit 0f2c599
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/view/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,28 +245,31 @@ export default class DiceView extends ItemView {
if (opts.expectedValue == ExpectedValue.None) {
opts.expectedValue = ExpectedValue.Roll;
}
const roller = await this.plugin.getRoller(formula, "view", opts);

if (!(roller instanceof StackRoller)) {
new Notice("The Dice Tray only supports dice rolls.");
return;
}
roller.iconEl.detach();
roller.containerEl.onclick = null;
roller.buildDiceTree();
if (!roller.dice.length) {
new Notice("Invalid formula.");
return;
try {
const roller =
await this.plugin.getRoller(formula, "view", opts)
.catch((e) => { throw e });
if (!(roller instanceof StackRoller)) {
throw new Error("The Dice Tray only supports dice rolls.")
}
roller.iconEl.detach();
roller.containerEl.onclick = null;
roller.buildDiceTree();
if (!roller.dice.length) {
throw new Error("No dice.")
}
await roller.roll(this.plugin.data.renderer)
.catch((e) => { throw e });
this.addResult(roller);
} catch (e) {
new Notice("Invalid Formula: " + e.message);
} finally {
this.rollButton.setDisabled(false);
this.buildButtons();
this.#formula = new Map();
this.#add = 0;
this.setFormula();
}
await roller.roll(this.plugin.data.renderer);
this.rollButton.setDisabled(false);

this.addResult(roller);

this.buildButtons();
this.#formula = new Map();
this.#add = 0;
this.setFormula();
}
buildFormula() {
this.formulaEl.empty();
Expand Down

0 comments on commit 0f2c599

Please sign in to comment.