Lucid debugging

How can I debug a Lucid method?

For example, if I save a user with User.save(payload) but something went wrong I don’t get any feedback as to what may have gone wrong.

I’ve turned on Mysql debugging via my .env using DB_DEBUG=true and run the server using adonis serve --dev --debug. I can see queries that are successful in my terminal, but if a Lucid method/query fails I don’t get anything except for a “Could not get any response” in Postman.

Here’s an example of the update method I’m trying to run

async update ({ request, response, params, auth }) {
    try {
      const user_id = auth.user.id
      const property_id = params.id
      const has_enquired = request.input('has_enquired')

      const payload = { 
        user_id,
        property_id,
        has_enquired
      }

      const property = await Property.save(payload)

      return response.ok(property)
    } catch (err) {
      return response
        .status(err.status)
        .send(err.message)
    }
  }

Any guidance on how to properly debug Lucid related issues would be much appreciated.

1 Like

I’ve just noticed I’m doing the save with a payload which is incorrect syntax. So that’s likely the issue, but nonetheless there’s no feedback indicating this - am I missing a config setting to get more verbose error logging?

1 Like

What if you just console.log() the error message before sending to the client?

catch (err) {
   console.log(err)
   return response
    .status(err.status)
    .send(err.message)
}

On your terminal you can see the error trace when the request hits the server and triggers an error.

1 Like

Thanks @begueradj, that seems so obvious now that you point it out :slight_smile: