nestjsx / nestjs-typeorm-paginate

:page_with_curl: Pagination response object function + types for typeorm + nestjs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EntityPropertyNotFound cause the server to stop

BraeschAntoine opened this issue · comments

Hello, i'm trying to build a generic service using this module.
It can result in using property not present in the entity, in the where clause of the FindManyOptions object passed to the paginate function.

I tried to surround the function with a try catch, but the EntityPropertyNotFound still persists and the server still stops.

After modifiying generated source coude (paginate.js), i found that it comes from the line 121 :

const [items, total] = yield Promise.all(promises);

The yield keyword is making the code fail, and stopping the server. With an await it works perfectly. I know you guys used an await in your .ts file, but is there something on your side or mine, to do to catch this error and let the server keep running despite the exception being raised ?

I'm working on Windows 11, with the repository version of the paginate function.

Let me know if you need some of my code.

So with the info you've provided I reckon that's an issue with your entity and or properties you've supplied within the query because that line where the yield is, is a generator. So an async method such as async () => await something(); is called a Promise and promises in JS have to be resolved in a weird way and that weird way is essentially generator methods where we yield a value

function* myGenerator() {
  yield 1
  yield 2
  yield 3
}

In that example, each time we call myGenerator() we get a different value from 1 to 3 depending on how many times we call it. I don't know why I'm explaining this in depth but I'd suggest you need to find your stack trace and hopefully that'll provide some info on what's going on.

My guess it'll be something like
nestjs-typeorm-paginate
typeorm
repository.get()

or something like that but your problem sounds like it's a query issue within your entity definition etc. Hopefully you solve it or have solved it?

Well yes the stack starts with a repository.get() as you said, but the problem is that i'm trying to create a generic implementation, so the field i'm putting in the paginate query might or might not exist, and it cause the stack to happen when the field does not exist on the effective entity. I don't know if my explaination is clear enough, tellme if you need anything else.

I didnt solve it (it was a year ago so a bit far for me) but i think i just implemented a field verification earlier in the process, to be sure i would not query on a field that does not exist.

Ahh I see, then I reckon the problem is that the entity property metadata might not exist in typeorm? And an exception is thrown there and you're unable to see it? Don't suppose you have the stack trace? From what I remember, typeorm stored all metadata of entities somewhere so perhaps use that method for verification of the property? Single source of truth would be easier to make sure you don't have this exception from typeorm