From 27616a0061beeb203d426294b457e33ae99c0229 Mon Sep 17 00:00:00 2001 From: Kyle Thornton Date: Wed, 16 Sep 2020 08:16:36 -0400 Subject: [PATCH] wrap button clicks in try catch to prevent script from hanging --- src/commands/texei/sharingcalc/recalculate.ts | 10 ++++-- src/commands/texei/sharingcalc/resume.ts | 32 +++++++++++-------- src/commands/texei/sharingcalc/suspend.ts | 30 +++++++++-------- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/commands/texei/sharingcalc/recalculate.ts b/src/commands/texei/sharingcalc/recalculate.ts index f168881..b0fb3ad 100644 --- a/src/commands/texei/sharingcalc/recalculate.ts +++ b/src/commands/texei/sharingcalc/recalculate.ts @@ -77,9 +77,13 @@ export default class Recalculate extends SfdxCommand { this.debug(`DEBUG Clicking 'Recalculate' button`); - await page.click( - `#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_recalc"].btn` - ); + try { + await page.click( + `#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_recalc"].btn` + ); + } catch (ex) { + console.log('Unable to recalculate sharing.', ex.message); + } await navigationPromise; diff --git a/src/commands/texei/sharingcalc/resume.ts b/src/commands/texei/sharingcalc/resume.ts index 33ed39e..1070037 100644 --- a/src/commands/texei/sharingcalc/resume.ts +++ b/src/commands/texei/sharingcalc/resume.ts @@ -78,20 +78,24 @@ export default class Resume extends SfdxCommand { this.debug(`DEBUG Clicking 'Resume' button`); - // Resume either Group Membership or Sharing Rules - if (this.flags.scope === "groupMembership") { - await page.click( - `#gmSect > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="group_resume"].btn` - ); - - // click the yes button to recaulcate group memberships immediately - await page.click( - `div#group_resume_dialog_buttons > input[value=" Yes "]` - ); - } else { - await page.click( - `#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_resume"].btn` - ); + try { + // Resume either Group Membership or Sharing Rules + if (this.flags.scope === "groupMembership") { + await page.click( + `#gmSect > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="group_resume"].btn` + ); + + // click the yes button to recaulcate group memberships immediately + await page.click( + `div#group_resume_dialog_buttons > input[value=" Yes "]` + ); + } else { + await page.click( + `#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_resume"].btn` + ); + } + } catch (ex) { + console.log('Unable to resume sharing.', ex.message); } await navigationPromise; diff --git a/src/commands/texei/sharingcalc/suspend.ts b/src/commands/texei/sharingcalc/suspend.ts index 00d8f17..e58b0cc 100644 --- a/src/commands/texei/sharingcalc/suspend.ts +++ b/src/commands/texei/sharingcalc/suspend.ts @@ -78,19 +78,23 @@ export default class Suspend extends SfdxCommand { this.debug(`DEBUG Clicking 'Suspend' button`); - // Suspend either Group Membership or Sharing Rules - if (this.flags.scope === "groupMembership") { - page.on("dialog", dialog => { - dialog.accept(); - }); - - await page.click( - `#gmSect > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="group_suspend"].btn` - ); - } else { - await page.click( - '#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_suspend"].btn' - ); + try { + // Suspend either Group Membership or Sharing Rules + if (this.flags.scope === "groupMembership") { + page.on("dialog", dialog => { + dialog.accept(); + }); + + await page.click( + `#gmSect > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="group_suspend"].btn` + ); + } else { + await page.click( + '#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_suspend"].btn' + ); + } + } catch (ex) { + console.log('Unable to suspend sharing.', ex.message); } await navigationPromise;