Skip to content

Commit dd20345

Browse files
committed
chore: error handling
1 parent 02d867d commit dd20345

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

src/handlers/comment-created-callback.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function issueCommentCreatedCallback(
2323
return { status: 204, reason: logger.info("Comment is empty. Skipping.").logMessage.raw };
2424
}
2525
logger.info(`Asking question: ${question}`);
26-
let commentToPost;
26+
2727
try {
2828
const response = await askQuestion(context, question);
2929
const { answer, tokenUsage } = response;
@@ -32,10 +32,10 @@ export async function issueCommentCreatedCallback(
3232
}
3333
logger.info(`Answer: ${answer}`, { tokenUsage });
3434
const tokens = `\n\n<!--\n${JSON.stringify(tokenUsage, null, 2)}\n--!>`;
35-
commentToPost = answer + tokens;
35+
const commentToPost = answer + tokens;
3636
await addCommentToIssue(context, commentToPost);
3737
return { status: 200, reason: logger.info("Comment posted successfully").logMessage.raw };
38-
} catch (err) {
39-
throw err;
38+
} catch (error) {
39+
throw await bubbleUpErrorComment(context, error, false);
4040
}
4141
}

src/handlers/comments.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { logger } from "../helpers/errors";
12
import { splitKey } from "../helpers/issue";
23
import { LinkedIssues, SimplifiedComment } from "../types/github-types";
34
import { StreamlinedComment } from "../types/llm";
@@ -53,7 +54,10 @@ export function createKey(issueUrl: string, issue?: number) {
5354
}
5455

5556
if (!key) {
56-
throw new Error("Invalid issue url");
57+
throw logger.error("Invalid issue URL", {
58+
issueUrl,
59+
issueNumber: issue,
60+
});
5761
}
5862

5963
if (key.includes("#")) {

src/helpers/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function bubbleUpErrorComment(context: Context, err: unknown, post
1616
if (err instanceof LogReturn) {
1717
errorMessage = err;
1818
} else if (err instanceof Error) {
19-
errorMessage = context.logger.error(err.message, { error: err });
19+
errorMessage = context.logger.error(err.message, { stack: err.stack });
2020
} else {
2121
errorMessage = context.logger.error("An error occurred", { err });
2222
}

src/helpers/issue-fetching.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function fetchLinkedIssues(params: FetchParams) {
4242
return { streamlinedComments: {}, linkedIssues: [], specAndBodies: {}, seen: new Set<string>() };
4343
}
4444
if (!issue.body || !issue.html_url) {
45-
throw logger.error("Issue body or URL not found");
45+
throw logger.error("Issue body or URL not found", { issueUrl: issue.html_url });
4646
}
4747

4848
if (!params.owner || !params.repo) {

src/helpers/issue.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createKey } from "../handlers/comments";
22
import { FetchedCodes, FetchParams, LinkedIssues } from "../types/github-types";
33
import { StreamlinedComment } from "../types/llm";
44
import { Context } from "../types/context"; // Import Context type
5+
import { logger } from "./errors";
56

67
/**
78
* Removes duplicate streamlined comments based on their body content.
@@ -239,7 +240,7 @@ export async function pullReadmeFromRepoForIssue(params: FetchParams): Promise<s
239240
readme = Buffer.from(response.data.content, "base64").toString();
240241
}
241242
} catch (error) {
242-
throw new Error(`Error fetching README from repository: ${error}`);
243+
throw logger.error(`Error fetching README from repository: ${error}`);
243244
}
244245
return readme;
245246
}

src/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// @ts-expect-error - no types found
12
import * as core from "@actions/core";
3+
// @ts-expect-error - no types found
24
import * as github from "@actions/github";
35
import { Value } from "@sinclair/typebox/value";
46
import { envSchema } from "./types/env";

0 commit comments

Comments
 (0)