module

Krikri::PluginHelpers::DbErrors

Shared PluginResult construction for the DB-family plugins' connection/query failure rescues (mysql_, postgresql_). The rescue CLAUSES must stay per-plugin (Crystal needs the concrete exception type at each site: DB::ConnectionRefused, PQ::PQError, MySql::Connection::PacketError), but the message shapes were seven hand-copied pairs - a format tweak (adding rc, redacting a URI) had to land seven times. One implementation now.

Class methods

connection_failed(ex : DB::ConnectionRefused, server : String) : PluginResult

"Could not connect to the PostgreSQL server: ..." shape.

Source
pg_connection_failed(ex : DB::ConnectionRefused, params : Hash(String, String)) : PluginResult

community.postgresql's connect_to_db() wraps every failed connect in module.fail_json(msg="unable to connect to database: %s"), where the detail is libpq's own connection-error text - not anything Crystal words itself. The plugin's raw params hash is passed so the message can quote the host/port or socket path the plugin actually dialed.

Source
query_failed(ex : Exception, server : String) : PluginResult

"PostgreSQL error: ..." / "MySQL error: ..." shape - for the dialect's own query-error exception raised mid-session.

Source