Skip to content
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

No session found error keeps crashing app. How to identify cause or return request error #82

Closed
efhan-the-unorthodox opened this issue May 6, 2022 · 3 comments

Comments

@efhan-the-unorthodox
Copy link

Background

I know that the community for this library is kinda small but also this is the library that I've seen that fits perfectly in my use case together with Prisma ORM. So basically I use this library alongside prisma as my session-store for storing sessions in my express app when users login. In my development environment, I don't seem to face any problem when logging in and usually the session is able to persist for the amount of time I gave (which was about 30 days). However, after putting into production, my testers on the client side have complained a few times already of losing connection to the server after doing typical CRUD functions. I looked into my logs and so far I've only managed to find this from the log which says as follows:

PrismaClientKnownRequestError: 
Invalid `this.prisma[this.sessionModelName].update()` invocation in
/app/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:483:81

  480     id: this.dbRecordIdIsSessionId ? sid : this.dbRecordIdFunction(sid),
  481 };
  482 if (!(existingSession !== null)) return [3 /*break*/, 4];
→ 483 return [4 /*yield*/, this.prisma[this.sessionModelName].update(
  An operation failed because it depends on one or more records that were required but not found. Record to update not found.
    at Object.request (/app/node_modules/@prisma/client/runtime/index.js:45629:15)
    at async PrismaClient._request (/app/node_modules/@prisma/client/runtime/index.js:46456:18) {
  code: 'P2025',
  clientVersion: '3.13.0',
  meta: { cause: 'Record to update not found.' }
}

So apparently from the error log, this is a Prisma Error of P2025 where it says "An operation failed because it depends on one or more records that were required but not found." In which apparently it couldn't find the record to update. However, this is the part where I don't understand because nowhere am I actually calling to check the session and whatever it is, is there a way to get the app to return an error rather than just crashing the entire server?

kleydon added a commit that referenced this issue May 10, 2022
Wraps set() function's create/update functions within a try/catch block.

When an error is caught, it is logged and supplied to a callback (if provided) as the callback's "error" argument. Addresses github issue #82.
kleydon pushed a commit that referenced this issue May 10, 2022
## [3.1.4](v3.1.3...v3.1.4) (2022-05-10)

### Bug Fixes

* prevent crash in set ([3c774eb](3c774eb)), closes [#82](#82)
@kleydon
Copy link
Owner

kleydon commented May 10, 2022

Hi @efhan-the-unorthodox - thanks for posting this issue.

I've just pushed a new release (3.1.4) via PR #84 that prevents the crash, while relaying the error, via express session store's convention for doing so.

store.set() takes a callback, which in turn takes an error argument, i.e. store.set(sid, session, (error)=>{...}); see here for the approach.

Going to close this for now... If problems persist - or if you learn more about the specific circumstances under which P2025 occurs - I'd love to know about it.

Cheers.

@kleydon kleydon closed this as completed May 10, 2022
@kleydon kleydon mentioned this issue May 10, 2022
@efhan-the-unorthodox
Copy link
Author

Hi @efhan-the-unorthodox - thanks for posting this issue.

I've just pushed a new release (3.1.4) via PR #84 that prevents the crash, while relaying the error, via express session store's convention for doing so.

store.set() takes a callback, which in turn takes an error argument, i.e. store.set(sid, session, (error)=>{...}); see here for the approach.

Going to close this for now... If problems persist - or if you learn more about the specific circumstances under which P2025 occurs - I'd love to know about it.

Cheers.

I know this is late. But thank you for the help. Much appreciated.

@kleydon
Copy link
Owner

kleydon commented Jun 14, 2022

👍

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

No branches or pull requests

2 participants