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

Commit

Permalink
fix: log level and error handling
Browse files Browse the repository at this point in the history
on the github comment it will make the metadata fully visible on fatals not just on errors now
  • Loading branch information
0x4007 committed Nov 27, 2023
1 parent bdcfb73 commit ac2534e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/adapters/supabase/helpers/pretty-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ export class PrettyLogs {
const fullLogString = logString;

const colorMap: Record<PrettyLogsWithOk, [keyof typeof console, Colors]> = {
error: ["error", Colors.fgRed],
fatal: ["error", Colors.fgRed],
ok: ["log", Colors.fgGreen],
warn: ["warn", Colors.fgYellow],
error: ["warn", Colors.fgYellow],
info: ["info", Colors.dim],
debug: ["debug", Colors.fgMagenta],
http: ["debug", Colors.dim],
Expand Down Expand Up @@ -194,8 +194,8 @@ enum Colors {
bgWhite = "\x1b[47m",
}
export enum LogLevel {
FATAL = "error",
ERROR = "warn",
FATAL = "fatal",
ERROR = "error",
INFO = "info",
HTTP = "http",
VERBOSE = "verbose",
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/supabase/helpers/tables/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ export class Logs {

private _diffColorCommentMessage(type: string, message: string) {
const diffPrefix = {
error: "-", // - text in red
fatal: "-", // - text in red
ok: "+", // + text in green
warn: "!", // ! text in orange
error: "!", // ! text in orange
// info: "#", // # text in gray
// debug: "@@@@",// @@ text in purple (and bold)@@
// error: null,
Expand Down
8 changes: 4 additions & 4 deletions src/bindings/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ export async function bindEvents(eventContext: ProbotContext) {
};

if (!context.config.keys.evmPrivateEncrypted) {
context.logger.warn("No EVM private key found");
context.logger.error("No EVM private key found");
}

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

if (eventContext.name === GitHubEvent.REPOSITORY_DISPATCH) {
const dispatchPayload = payload as any;
const dispatchPayload = payload;
if (payload.action === "issueClosed") {
//This is response for issueClosed request
const response = dispatchPayload.client_payload.result;

Check failure on line 101 in src/bindings/event.ts

View workflow job for this annotation

GitHub Actions / e2e-test

Property 'client_payload' does not exist on type '{ issue?: { number: number; id: number; node_id: string; url: string; html_url: string; events_url: string; assignee: { id: number; node_id: string; url: string; login: string; avatar_url: string; gravatar_id: string | null; ... 11 more ...; site_admin: boolean; } | null; ... 15 more ...; user: { ...; }; } | undefin...'.

Check failure on line 101 in src/bindings/event.ts

View workflow job for this annotation

GitHub Actions / build

Property 'client_payload' does not exist on type '{ issue?: { number: number; id: number; node_id: string; url: string; html_url: string; events_url: string; assignee: { id: number; node_id: string; url: string; login: string; avatar_url: string; gravatar_id: string | null; ... 11 more ...; site_admin: boolean; } | null; ... 15 more ...; user: { ...; }; } | undefin...'.
Expand All @@ -114,7 +114,7 @@ export async function bindEvents(eventContext: ProbotContext) {
const handlers = processors[eventName];

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

Expand Down Expand Up @@ -222,7 +222,7 @@ function createRenderCatchAll(context: Context, handlerType: AllHandlersWithType
const prettySerialized = JSON.stringify(report.metadata, null, 2);
// first check if metadata is an error, then post it as a json comment
// otherwise post it as an html comment
if (report.logMessage.type === ("error" as LogMessage["type"])) {
if (report.logMessage.type === ("fatal" as LogMessage["type"])) {
metadataSerialized = ["```json", prettySerialized, "```"].join("\n");
} else {
metadataSerialized = ["<!--", prettySerialized, "-->"].join("\n");
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/comment/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function commentCreatedOrEdited(context: Context) {
const isDisabled = config.disabledCommands.some((command) => command === id.replace("/", ""));

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

return await handler(context, body);
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/comment/handlers/issue/assignee-scoring.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Decimal from "decimal.js";
import { Context } from "../../../../types/context";
import { Issue, User } from "../../../../types/payload";
import { ContributorView } from "./contribution-style-types";
import { UserScoreDetails } from "./issue-shared-types";
import { Context } from "../../../../types/context";

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

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

if (!priceLabel) {
throw context.logger.warn("Price label is undefined");
throw context.logger.error("Price label is undefined");
}

// get the price
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/comment/handlers/issue/generate-permits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function generateComment(context: Context, totals: TotalsById) {
const contributorName = userTotals.user.login;
// const contributionClassName = userTotals.details[0].contribution as ContributorClassNames;

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

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

Expand Down
6 changes: 3 additions & 3 deletions src/handlers/comment/handlers/issue/issue-closed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ async function preflightChecks({ issue, issueComments, context }: PreflightCheck
if (config.features.publicAccessControl.fundExternalClosedIssue) {
const hasPermission = await checkUserPermissionForRepoAndOrg(context, payload.sender.login);
if (!hasPermission)
throw context.logger.warn(
throw context.logger.error(
"Permit generation disabled because this issue has been closed by an external contributor."
);
}

const priceLabels = issue.labels.find((label) => label.name.startsWith("Price: "));
if (!priceLabels) {
throw context.logger.warn("No price label has been set. Skipping permit generation.", {
throw context.logger.error("No price label has been set. Skipping permit generation.", {
labels: issue.labels,
});
}
Expand All @@ -110,7 +110,7 @@ function checkIfPermitsAlreadyPosted(context: Context, botComments: Comment[]) {
if (parsed.caller === "generatePermits") {
// in the comment metadata we store what function rendered the comment
console.trace({ parsed });
throw context.logger.warn("Permit already posted");
throw context.logger.error("Permit already posted");
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/check-github-rate-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function checkRateLimitGit(headers: { "x-ratelimit-remaining"?: str
const now = new Date();
const timeToWait = resetTime.getTime() - now.getTime();
const logger = Runtime.getState().logger;
logger.warn("No remaining requests.", { resetTime, now, timeToWait });
logger.error("No remaining requests.", { resetTime, now, timeToWait });
await wait(timeToWait);
}
return remainingRequests;
Expand Down

0 comments on commit ac2534e

Please sign in to comment.