Skip to content

Commit

Permalink
fix: removed duplicate error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Sep 30, 2024
1 parent c9fc81c commit 3f61f14
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/worker-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
id: wrangler_deploy
uses: cloudflare/wrangler-action@v3
with:
wranglerVersion: "3.57.0"
wranglerVersion: "3.78"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
secrets: |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"tsx": "4.15.6",
"typescript": "5.4.5",
"typescript-eslint": "7.13.1",
"wrangler": "3.60.3"
"wrangler": "3.78.12"
},
"lint-staged": {
"*.ts": [
Expand Down
20 changes: 9 additions & 11 deletions src/handlers/shared/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function start(
const { taskStaleTimeoutDuration } = config;

if (!sender) {
throw new Error(logger.error(`Skipping '/start' since there is no sender in the context.`).logMessage.raw);
throw logger.error(`Skipping '/start' since there is no sender in the context.`);
}

// is it a child issue?
Expand All @@ -27,7 +27,7 @@ export async function start(
context,
"```diff\n# Please select a child issue from the specification checklist to work on. The '/start' command is disabled on parent issues.\n```"
);
throw new Error(logger.error(`Skipping '/start' since the issue is a parent issue`).logMessage.raw);
throw logger.error(`Skipping '/start' since the issue is a parent issue`);
}

let commitHash: string | null = null;
Expand All @@ -46,19 +46,17 @@ export async function start(
// is it assignable?

if (issue.state === ISSUE_TYPE.CLOSED) {
throw new Error(logger.error("This issue is closed, please choose another.", { issueNumber: issue.number }).logMessage.raw);
throw logger.error("This issue is closed, please choose another.", { issueNumber: issue.number });
}

const assignees = issue?.assignees ?? [];

// find out if the issue is already assigned
if (assignees.length !== 0) {
const isCurrentUserAssigned = !!assignees.find((assignee) => assignee?.login === sender.login);
throw new Error(
logger.error(
isCurrentUserAssigned ? "You are already assigned to this task." : "This issue is already assigned. Please choose another unassigned task.",
{ issueNumber: issue.number }
).logMessage.raw
throw logger.error(
isCurrentUserAssigned ? "You are already assigned to this task." : "This issue is already assigned. Please choose another unassigned task.",
{ issueNumber: issue.number }
);
}

Expand All @@ -81,15 +79,15 @@ export async function start(
}

if (error) {
throw new Error(logger.error(error, { issueNumber: issue.number }).logMessage.raw);
throw logger.error(error, { issueNumber: issue.number });
}

// get labels
const labels = issue.labels ?? [];
const priceLabel = labels.find((label: Label) => label.name.startsWith("Price: "));

if (!priceLabel) {
throw new Error(logger.error("No price label is set to calculate the duration", { issueNumber: issue.number }).logMessage.raw);
throw logger.error("No price label is set to calculate the duration", { issueNumber: issue.number });
}

const deadline = getDeadline(labels);
Expand Down Expand Up @@ -161,7 +159,7 @@ async function handleTaskLimitChecks(username: string, context: Context, logger:
}

if (await hasUserBeenUnassigned(context, username)) {
throw new Error(logger.error(`${username} you were previously unassigned from this task. You cannot be reassigned.`, { username }).logMessage.raw);
throw logger.error(`${username} you were previously unassigned from this task. You cannot be reassigned.`, { username });
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/shared/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function stop(
const userToUnassign = assignees.find((assignee: Partial<Assignee>) => assignee?.login?.toLowerCase() === sender.login.toLowerCase());

if (!userToUnassign) {
throw new Error(logger.error("You are not assigned to this task", { issueNumber, user: sender.login })?.logMessage.raw as string);
throw logger.error("You are not assigned to this task", { issueNumber, user: sender.login });
}

// close PR
Expand Down
6 changes: 2 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ export async function startStopTask(inputs: PluginInputs, env: Env) {
let errorMessage;
if (err instanceof LogReturn) {
errorMessage = err;
} else if (err instanceof Error) {
errorMessage = context.logger.error(err.message, { error: err });
await addCommentToIssue(context, `${errorMessage?.logMessage.diff}\n<!--\n${sanitizeMetadata(errorMessage?.metadata)}\n-->`);
} else {
errorMessage = context.logger.error("An error occurred", { err });
context.logger.error("An error occurred", { err });
}
await addCommentToIssue(context, `${errorMessage?.logMessage.diff}\n<!--\n${sanitizeMetadata(errorMessage?.metadata)}\n-->`);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/utils/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ async function confirmMultiAssignment(context: Context, issueNumber: number, use
});

if (!assignees?.length) {
throw new Error(
logger.error("We detected that this task was not assigned to anyone. Please report this to the maintainers.", { issueNumber, usernames }).logMessage.raw
);
throw logger.error("We detected that this task was not assigned to anyone. Please report this to the maintainers.", { issueNumber, usernames });
}

if (isPrivate && assignees?.length <= 1) {
Expand Down
3 changes: 3 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ compatibility_date = "2024-05-23"
node_compat = true
[env.dev]
[env.prod]

[observability]
enabled = true
Loading

0 comments on commit 3f61f14

Please sign in to comment.