Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit ac2534e

Browse files
committed
fix: log level and error handling
on the github comment it will make the metadata fully visible on fatals not just on errors now
1 parent bdcfb73 commit ac2534e

File tree

8 files changed

+19
-19
lines changed

8 files changed

+19
-19
lines changed

src/adapters/supabase/helpers/pretty-logs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ export class PrettyLogs {
140140
const fullLogString = logString;
141141

142142
const colorMap: Record<PrettyLogsWithOk, [keyof typeof console, Colors]> = {
143-
error: ["error", Colors.fgRed],
143+
fatal: ["error", Colors.fgRed],
144144
ok: ["log", Colors.fgGreen],
145-
warn: ["warn", Colors.fgYellow],
145+
error: ["warn", Colors.fgYellow],
146146
info: ["info", Colors.dim],
147147
debug: ["debug", Colors.fgMagenta],
148148
http: ["debug", Colors.dim],
@@ -194,8 +194,8 @@ enum Colors {
194194
bgWhite = "\x1b[47m",
195195
}
196196
export enum LogLevel {
197-
FATAL = "error",
198-
ERROR = "warn",
197+
FATAL = "fatal",
198+
ERROR = "error",
199199
INFO = "info",
200200
HTTP = "http",
201201
VERBOSE = "verbose",

src/adapters/supabase/helpers/tables/logs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ export class Logs {
323323

324324
private _diffColorCommentMessage(type: string, message: string) {
325325
const diffPrefix = {
326-
error: "-", // - text in red
326+
fatal: "-", // - text in red
327327
ok: "+", // + text in green
328-
warn: "!", // ! text in orange
328+
error: "!", // ! text in orange
329329
// info: "#", // # text in gray
330330
// debug: "@@@@",// @@ text in purple (and bold)@@
331331
// error: null,

src/bindings/event.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ export async function bindEvents(eventContext: ProbotContext) {
8787
};
8888

8989
if (!context.config.keys.evmPrivateEncrypted) {
90-
context.logger.warn("No EVM private key found");
90+
context.logger.error("No EVM private key found");
9191
}
9292

9393
if (!context.logger) {
9494
throw new Error("Failed to create logger");
9595
}
9696

9797
if (eventContext.name === GitHubEvent.REPOSITORY_DISPATCH) {
98-
const dispatchPayload = payload as any;
98+
const dispatchPayload = payload;
9999
if (payload.action === "issueClosed") {
100100
//This is response for issueClosed request
101101
const response = dispatchPayload.client_payload.result;
@@ -114,7 +114,7 @@ export async function bindEvents(eventContext: ProbotContext) {
114114
const handlers = processors[eventName];
115115

116116
if (!handlers) {
117-
return context.logger.warn("No handler configured for event:", { eventName });
117+
return context.logger.error("No handler configured for event:", { eventName });
118118
}
119119
const { pre, action, post } = handlers;
120120

@@ -222,7 +222,7 @@ function createRenderCatchAll(context: Context, handlerType: AllHandlersWithType
222222
const prettySerialized = JSON.stringify(report.metadata, null, 2);
223223
// first check if metadata is an error, then post it as a json comment
224224
// otherwise post it as an html comment
225-
if (report.logMessage.type === ("error" as LogMessage["type"])) {
225+
if (report.logMessage.type === ("fatal" as LogMessage["type"])) {
226226
metadataSerialized = ["```json", prettySerialized, "```"].join("\n");
227227
} else {
228228
metadataSerialized = ["<!--", prettySerialized, "-->"].join("\n");

src/handlers/comment/action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function commentCreatedOrEdited(context: Context) {
3535
const isDisabled = config.disabledCommands.some((command) => command === id.replace("/", ""));
3636

3737
if (isDisabled && id !== "/help") {
38-
return logger.warn("Skipping because it is disabled on this repo.", { id });
38+
return logger.error("Skipping because it is disabled on this repo.", { id });
3939
}
4040

4141
return await handler(context, body);

src/handlers/comment/handlers/issue/assignee-scoring.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Decimal from "decimal.js";
2+
import { Context } from "../../../../types/context";
23
import { Issue, User } from "../../../../types/payload";
34
import { ContributorView } from "./contribution-style-types";
45
import { UserScoreDetails } from "./issue-shared-types";
5-
import { Context } from "../../../../types/context";
66

77
export async function assigneeScoring(
88
context: Context,
@@ -18,7 +18,7 @@ export async function assigneeScoring(
1818
): Promise<UserScoreDetails[]> {
1919
// get the price label
2020
const priceLabels = issue.labels.filter((label) => label.name.startsWith("Price: "));
21-
if (!priceLabels) throw context.logger.warn("Price label is undefined");
21+
if (!priceLabels) throw context.logger.error("Price label is undefined");
2222

2323
// get the smallest price label
2424
const priceLabel = priceLabels
@@ -31,7 +31,7 @@ export async function assigneeScoring(
3131
?.shift();
3232

3333
if (!priceLabel) {
34-
throw context.logger.warn("Price label is undefined");
34+
throw context.logger.error("Price label is undefined");
3535
}
3636

3737
// get the price

src/handlers/comment/handlers/issue/generate-permits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function generateComment(context: Context, totals: TotalsById) {
4343
const contributorName = userTotals.user.login;
4444
// const contributionClassName = userTotals.details[0].contribution as ContributorClassNames;
4545

46-
if (!evmPrivateEncrypted) throw context.logger.warn("No bot wallet private key defined");
46+
if (!evmPrivateEncrypted) throw context.logger.error("No bot wallet private key defined");
4747

4848
const beneficiaryAddress = await runtime.adapters.supabase.wallet.getAddress(parseInt(userId));
4949

src/handlers/comment/handlers/issue/issue-closed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ async function preflightChecks({ issue, issueComments, context }: PreflightCheck
8686
if (config.features.publicAccessControl.fundExternalClosedIssue) {
8787
const hasPermission = await checkUserPermissionForRepoAndOrg(context, payload.sender.login);
8888
if (!hasPermission)
89-
throw context.logger.warn(
89+
throw context.logger.error(
9090
"Permit generation disabled because this issue has been closed by an external contributor."
9191
);
9292
}
9393

9494
const priceLabels = issue.labels.find((label) => label.name.startsWith("Price: "));
9595
if (!priceLabels) {
96-
throw context.logger.warn("No price label has been set. Skipping permit generation.", {
96+
throw context.logger.error("No price label has been set. Skipping permit generation.", {
9797
labels: issue.labels,
9898
});
9999
}
@@ -110,7 +110,7 @@ function checkIfPermitsAlreadyPosted(context: Context, botComments: Comment[]) {
110110
if (parsed.caller === "generatePermits") {
111111
// in the comment metadata we store what function rendered the comment
112112
console.trace({ parsed });
113-
throw context.logger.warn("Permit already posted");
113+
throw context.logger.error("Permit already posted");
114114
}
115115
}
116116
});

src/utils/check-github-rate-limit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function checkRateLimitGit(headers: { "x-ratelimit-remaining"?: str
77
const now = new Date();
88
const timeToWait = resetTime.getTime() - now.getTime();
99
const logger = Runtime.getState().logger;
10-
logger.warn("No remaining requests.", { resetTime, now, timeToWait });
10+
logger.error("No remaining requests.", { resetTime, now, timeToWait });
1111
await wait(timeToWait);
1212
}
1313
return remainingRequests;

0 commit comments

Comments
 (0)