Source of unhandled exceptions

On my server I get an error like the following:

Not found err ModelNotFoundException: E_MISSING_DATABASE_ROW: Cannot find database row for Staff model

More details: https://err.sh/adonisjs/errors/E_MISSING_DATABASE_ROW
at Function.raise (node_modules/@adonisjs/lucid/src/Exceptions/index.js:143:12)
at Proxy.firstOrFail (node_modules/@adonisjs/lucid/src/Lucid/QueryBuilder/index.js:434:39)

The problem that I have is in that this error does not indicate the location of where this error happened so it is difficult to trace back and find the source.

I do use findOrFail throughout my web app to handle verifying an instance exists before going ahead to use it. However when I do use it in the context of my API, it does not log me an error since I return it.

show({ params }) {
  return User.findOrFail(params.id);
}

This method will either return the user or give back a 404 error which I can catch on the frontend to show the error that the user could not be found… This is the intended workflow and behavior.

However I’ve been starring at days at my server logs trying to understand where the error I’ve provided here comes from but I have had no success.

Scrolling through my logs I can see that it happens very regularly after users make a GET request to 2 URLs but in those 2 URLs I make no reference to the Staff model.

You can try turning on debug mode in config/database.js to see all queries that are happening

Thank you for the tip! I turned this on and I was able to see what was causing my errors and fix it.