Skip to content

Commit 3a911d0

Browse files
authored
fix: refactor force rejection; properly update states; report with clearer logs (#143)
1 parent 9695415 commit 3a911d0

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/commands/reject.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,22 @@ export default class RejectCommand extends SlashCommand {
9898

9999
const rejectionResult = await forceReject(member, submission, template)
100100

101-
if (rejectionResult.error) {
102-
if (rejectionResult.message === 'didnt-run-cleanup' && template.location() === 'thread') {
101+
if (rejectionResult.outcome !== 'success') {
102+
// Cleanup was not selected to run. This is controlled by the templates (public templates are not cleaned up)
103+
if (rejectionResult.outcome === 'cleanup-not-run') {
103104
return commandLog.info({
104105
type: 'text',
105-
content: 'Could not cleanup, submission was errored. Please cleanup manually.',
106+
content: `Did not clean up the project messages/threads, that operation is not applicable for the chosen template.
107+
Please clean up manually by closing the thread, and deleting the submission message.`,
106108
ctx,
107109
extraOpts: {
108110
ephemeral: false
109111
}
110112
})
111113
}
112114

115+
// The template actually hit an error, log it and tell users to send the message themselves
116+
113117
const templatedReason = template.execute({
114118
user: `<@${submission.authorId}>`,
115119
name: submission.name
@@ -132,13 +136,6 @@ export default class RejectCommand extends SlashCommand {
132136
content: rejectionResult.message,
133137
ctx: submission
134138
})
135-
136-
return
137139
}
138-
139-
assert(
140-
rejectionResult.outcome === 'instant-reject',
141-
'result did not have outcome instant-reject'
142-
)
143140
}
144141
}

src/vote/action.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,21 @@ export async function reject (
265265
}
266266
}
267267

268+
interface RejectionOk {
269+
outcome: 'success'
270+
}
271+
272+
interface RejectionErr {
273+
outcome: 'error'
274+
message: string
275+
}
276+
277+
interface RejectionCleanupNotRun {
278+
outcome: 'cleanup-not-run'
279+
}
280+
281+
export type RejectionResult = RejectionOk | RejectionErr | RejectionCleanupNotRun
282+
268283
/**
269284
* Forcefully reject a submission, this will run cleanup for the submission.
270285
*/
@@ -273,7 +288,7 @@ export async function forceReject (
273288
// Could be in the pending state, we will just ignore warnings if that is the case
274289
submission: ValidatedSubmission | PendingSubmission,
275290
template: RejectionTemplate
276-
): Promise<VoteModificationResult> {
291+
): Promise<RejectionResult> {
277292
// Do not allow paused submissions to be rejected, this should be checked by the caller
278293
// Errored submissions are acceptable because invalid-id cases will be in the error state
279294
// This case should be validated by callers
@@ -295,6 +310,7 @@ export async function forceReject (
295310
user: `<@${submission.authorId}>`,
296311
name: submission.name
297312
})
313+
298314
await runCatching(
299315
async () =>
300316
await publicLogs.send({
@@ -326,7 +342,7 @@ export async function forceReject (
326342
}
327343
} catch (err) {
328344
return {
329-
error: true,
345+
outcome: 'error',
330346
message: `Failed to send rejection message: ${err}`
331347
}
332348
}
@@ -366,12 +382,11 @@ export async function forceReject (
366382
ctx: submission
367383
})
368384

385+
await updateSubmissionState(submission, 'DENIED')
386+
369387
if (!shouldRunCleanup) {
370-
// Not an ideal abort from here, but it's the easiest way to go about it.
371-
// This is an extreme edge case for the API design to handle.
372388
return {
373-
error: true,
374-
message: 'didnt-run-cleanup'
389+
outcome: 'cleanup-not-run'
375390
}
376391
}
377392

@@ -383,8 +398,7 @@ export async function forceReject (
383398
}, 'suppress')
384399

385400
return {
386-
error: false,
387-
outcome: 'instant-reject'
401+
outcome: 'success'
388402
}
389403
}
390404

@@ -401,8 +415,7 @@ export async function forceReject (
401415
}, 'suppress')
402416

403417
return {
404-
error: false,
405-
outcome: 'instant-reject'
418+
outcome: 'success'
406419
}
407420
}
408421

0 commit comments

Comments
 (0)