Skip to content

fix(cache): make dummy cache error ignorable #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Nov 22, 2024

All "dummy" cache methods throw by design.
This PR makes the corresponding errors ignorable so that the logs are less verbose and always use the DEBUG level.

All "dummy" cache methods throw by design.
This PR makes the corresponding errors ignorable so that the logs are less verbose and always use the DEBUG level.
Copy link

changeset-bot bot commented Nov 22, 2024

🦋 Changeset detected

Latest commit: 920a7fd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@opennextjs/aws Patch
app-pages-router Patch
app-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Nov 22, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 22.33% 1676 / 7503
🔵 Statements 22.33% 1676 / 7503
🔵 Functions 55.05% 98 / 178
🔵 Branches 69.41% 413 / 595
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/open-next/src/adapters/cache.ts 77.13% 80.89% 85.71% 77.13% 112-113, 174-176, 179-187, 197, 242-253, 280, 409-418, 422, 433-478
packages/open-next/src/overrides/incrementalCache/dummy.ts 0% 0% 0% 0% 1-17
packages/open-next/src/utils/error.ts 25% 20% 25% 25% 13-20, 32-39, 43-50
Generated in workflow #774 for commit 920a7fd by the Vitest Coverage Report Action

Copy link

pkg-pr-new bot commented Nov 22, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@opennextjs/aws@641

commit: 920a7fd

@vicb vicb force-pushed the cache-error branch 2 times, most recently from 33feaa9 to 15da503 Compare November 22, 2024 12:22
@vicb vicb requested a review from conico974 November 22, 2024 12:23
@vicb vicb changed the title feat(cache): make dummy cache error ignorable fix(cache): make dummy cache error ignorable Nov 22, 2024
Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

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

We may want to introduce another env variable OPEN_NEXT_ERROR_LOG_LEVEL to decide if we log the IgnorableError even in debug.
All of this would be decided inside the error function
By default it would only log level 1 error and above

@@ -192,7 +193,11 @@ export default class S3Cache {
} as CacheHandlerValue;
} catch (e) {
// We can usually ignore errors here as they are usually due to cache not being found
debug("Failed to get fetch cache", e);
if (isIgnorableError(e)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to do this here, error should already be handling this

export function error(...args: any[]) {
// we try to catch errors from the aws-sdk client and downplay some of them
if (
args.some((arg: AwsSdkClientCommandErrorLog) => isDownplayedErrorLog(arg))
) {
debug(...args);
} else if (args.some((arg) => arg.__openNextInternal)) {
// In case of an internal error, we log it with the appropriate log level
const error = args.find(
(arg) => arg.__openNextInternal,
) as BaseOpenNextError;
if (error.logLevel === 0) {
debug(...args);
return;
}
if (error.logLevel === 1) {
warn(...args);
return;
}
console.error(...args);
return;
} else {
console.error(...args);
}
}

Having only the error function deciding which error to log is probably better (and easier to read)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I better understand what you meant now (I didn't noticed the handling of internal errors in the logger).

Still I find having IgnorableErrors and OPEN_NEXT_ERROR_LOG_LEVEL a bit overkill.

Let me think more about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think IgnorableError alone are enough in most cases, debug mode should never be used outside of when you debug so you should never see such errors in production.
The OPEN_NEXT_ERROR_LOG_LEVEL has 1 main use imo, it's for adding the ability to mask RecoverableError logs, but it could also be used to mask IgnorableError in debug mode, which could be useful for us when testing something that has nothing to do with these errors

@vicb
Copy link
Contributor Author

vicb commented Nov 26, 2024

See #649

@vicb vicb closed this Nov 26, 2024
@vicb vicb deleted the cache-error branch November 26, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants