Skip to content

Commit 46e86b0

Browse files
committed
UnblockReview: throw error when multiple identical requests open
less risky than responding to the wrong one fixes #232 fixes #255
1 parent b775f1e commit 46e86b0

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

UnblockReview/main.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Many additional bugs fixed.
7575
const appealReason = hrEl.nextElementSibling.nextElementSibling.childNodes[ 0 ].textContent;
7676
// FIXME: should handle this case (|reason=\nText, https://github.com/NovemLinguae/UserScripts/issues/240) instead of throwing an error
7777
if ( appealReason === '\n' ) {
78-
mw.notify( 'UnblockReview error 1: unable to find decline reason by scanning HTML', { type: 'error' } );
78+
mw.notify( 'UnblockReview error: unable to find decline reason by scanning HTML', { type: 'error' } );
7979
return;
8080
}
8181

@@ -86,15 +86,22 @@ Many additional bugs fixed.
8686
// eslint-disable-next-line no-undef
8787
const unblockReview = new UnblockReview();
8888
const acceptDeclineReason = reasonArea.value;
89-
const wikitext2 = unblockReview.processAcceptOrDecline(
90-
wikitext,
91-
appealReason,
92-
acceptDeclineReason,
93-
DEFAULT_DECLINE_REASON,
94-
acceptOrDecline
95-
);
89+
let wikitext2;
90+
try {
91+
wikitext2 = unblockReview.processAcceptOrDecline(
92+
wikitext,
93+
appealReason,
94+
acceptDeclineReason,
95+
DEFAULT_DECLINE_REASON,
96+
acceptOrDecline
97+
);
98+
} catch ( e ) {
99+
mw.notify( 'UnblockReview error: ' + e.message, { type: 'error' } );
100+
return;
101+
}
102+
96103
if ( wikitext === wikitext2 ) {
97-
mw.notify( 'UnblockReview error 2: unable to determine write location.', { type: 'error' } );
104+
mw.notify( 'UnblockReview error: unable to determine write location.', { type: 'error' } );
98105
return;
99106
}
100107

UnblockReview/modules/UnblockReview.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export class UnblockReview {
3737
// eslint-disable-next-line no-useless-concat
3838
const negativeLookbehinds = '(?<!<' + 'nowiki>)';
3939
const regEx = new RegExp( negativeLookbehinds + this.escapeRegExp( initialText + paramsAndReason ), 'g' );
40+
const count = ( wikitext.match( regEx ) || [] ).length;
41+
if ( count > 1 ) {
42+
throw new Error( 'Too many matching unblock templates found' );
43+
}
44+
4045
const templateName = initialText.match( /^\{\{([A-Za-z-]+)/i )[ 1 ];
4146
let wikitext2 = wikitext.replace(
4247
regEx,
@@ -58,7 +63,7 @@ export class UnblockReview {
5863
}
5964

6065
if ( wikitext === wikitext2 ) {
61-
throw new Error( 'Replacing text with unblock message failed!' );
66+
throw new Error( 'Replacing text with unblock message failed' );
6267
}
6368

6469
// get rid of any [#*:] in front of {{unblock X}} templates. indentation messes up the background color and border of the unblock template.

0 commit comments

Comments
 (0)