Skip to content

Commit

Permalink
fix: Just reducing error log spam a bit (#306)
Browse files Browse the repository at this point in the history
* fix: Just reducing error log spam a bit
  • Loading branch information
dkershner6 authored Nov 9, 2023
1 parent 5a02285 commit f580cfa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/open-next/src/adapters/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default class S3Cache {
},
} as CacheHandlerValue;
} else {
error("Unknown cache type", cacheData);
warn("Unknown cache type", cacheData);
return null;
}
} catch (e) {
Expand Down Expand Up @@ -490,7 +490,7 @@ export default class S3Cache {
);
return result;
} catch (e) {
error("This error can usually be ignored : ", e);
warn("This error can usually be ignored : ", e);
return { Body: null, LastModified: null };
}
}
Expand Down
37 changes: 37 additions & 0 deletions packages/open-next/src/adapters/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,44 @@ export function warn(...args: any[]) {
console.warn(...args);
}

interface AwsSdkClientCommandErrorLog {
clientName: string;
commandName: string;
error: Error & { Code?: string };
}

type AwsSdkClientCommandErrorInput = Pick<
AwsSdkClientCommandErrorLog,
"clientName" | "commandName"
> & {
errorName: string;
};

const DOWNPLAYED_ERROR_LOGS: AwsSdkClientCommandErrorInput[] = [
{
clientName: "S3Client",
commandName: "GetObjectCommand",
errorName: "NoSuchKey",
},
];

const isDownplayedErrorLog = (errorLog: AwsSdkClientCommandErrorLog) =>
DOWNPLAYED_ERROR_LOGS.some(
(downplayedInput) =>
downplayedInput.clientName === errorLog?.clientName &&
downplayedInput.commandName === errorLog?.commandName &&
(downplayedInput.errorName === errorLog?.error?.name ||
downplayedInput.errorName === errorLog?.error?.Code),
);

export function error(...args: any[]) {
if (
args.some((arg: AwsSdkClientCommandErrorLog) => isDownplayedErrorLog(arg))
) {
warn(...args);
return;
}

console.error(...args);
}

Expand Down

1 comment on commit f580cfa

@vercel
Copy link

@vercel vercel bot commented on f580cfa Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

open-next – ./

open-next-git-main-sst-dev.vercel.app
open-next-sst-dev.vercel.app
open-next.vercel.app

Please sign in to comment.