kysely-org / kysely-ctl

Command-line tool for Kysely
MIT License
46 stars 1 forks source link

Migration error message do not include any details on connection error #64

Closed rafsawicki closed 2 days ago

rafsawicki commented 5 days ago

When trying to run migrations today I received the following error:

kysely migrate up   
◐ Starting migration up                                                                                                                                                                                                                       
✖ Migration failed with AggregateError   

This provides no information that could help with debugging the issue. Manually adding console.log(error) directly above the current Migration failed with logging code, reveals the following details.

kysely migrate up   
◐ Starting migration up                                                                      
AggregateError
    at internalConnectMultiple (node:net:1114:18)
    at afterConnectMultiple (node:net:1667:5) {
  code: 'ECONNREFUSED',
  fatal: true,
  [errors]: [
    Error: connect ECONNREFUSED ::1:3306
        at createConnectionError (node:net:1634:14)
        at afterConnectMultiple (node:net:1664:40) {
      errno: -61,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '::1',
      port: 3306
    },
    Error: connect ECONNREFUSED 127.0.0.1:3306
        at createConnectionError (node:net:1634:14)
        at afterConnectMultiple (node:net:1664:40) {
      errno: -61,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '127.0.0.1',
      port: 3306
    }
  ]
}
✖ Migration failed with AggregateError

So the kysely-ctl has access to all the details, but the current error message parsing - basically calling toString on the object by putting it as a part of the string template - is not sufficient to show them.

Not sure what is the best solution here, since errors can come from various libraries depending on the connection type. However, I've seen the same error message when running migrations on a postgres database, so it's definitely not limited just to mysql connection. I haven't had this issue with other error types, so maybe checking if an error that is thrown is an AggregateError, and adding a custom formatting for it, would be sufficient?

igalklebanov commented 2 days ago

Hey 👋

Thanks for raising this.

igalklebanov commented 2 days ago

Released in https://github.com/kysely-org/kysely-ctl/releases/tag/v0.8.10.