fix: logging the Haskell type instead of the listener error message directly
Previously: Just "connection error..." Now: connection error...
This commit is contained in:
@@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- Fix OpenAPI specification incorrectly exposing GET methods for volatile functions by @joelonsql in #4174
|
- Fix OpenAPI specification incorrectly exposing GET methods for volatile functions by @joelonsql in #4174
|
||||||
- Fix empty spread embeddings return unexpected SQL error by @taimoorzaeem in #3887
|
- Fix empty spread embeddings return unexpected SQL error by @taimoorzaeem in #3887
|
||||||
- Fix `/metrics` endpoint not responding with `Content-Type` header by @taimoorzaeem in #4271
|
- Fix `/metrics` endpoint not responding with `Content-Type` header by @taimoorzaeem in #4271
|
||||||
|
- Fix logging the Haskell type instead of the listener error message directly by @laurenceisla in #3588
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -110,11 +110,8 @@ observationMessage = \case
|
|||||||
DBListenStart channel -> do
|
DBListenStart channel -> do
|
||||||
"Listening for database notifications on the " <> show channel <> " channel"
|
"Listening for database notifications on the " <> show channel <> " channel"
|
||||||
DBListenFail channel listenErr ->
|
DBListenFail channel listenErr ->
|
||||||
"Failed listening for database notifications on the " <> show channel <> " channel. " <> (
|
"Failed listening for database notifications on the " <> show channel <> " channel. " <>
|
||||||
case listenErr of
|
either showListenerConnError showListenerException listenErr
|
||||||
Left err -> show err
|
|
||||||
Right err -> showListenerError err
|
|
||||||
)
|
|
||||||
DBListenRetry delay ->
|
DBListenRetry delay ->
|
||||||
"Retrying listening for database notifications in " <> (show delay::Text) <> " seconds..."
|
"Retrying listening for database notifications in " <> (show delay::Text) <> " seconds..."
|
||||||
DBListenerGotSCacheMsg channel ->
|
DBListenerGotSCacheMsg channel ->
|
||||||
@@ -163,8 +160,11 @@ observationMessage = \case
|
|||||||
|
|
||||||
jsonMessage err = T.decodeUtf8 . LBS.toStrict . Error.errorPayload $ Error.PgError False err
|
jsonMessage err = T.decodeUtf8 . LBS.toStrict . Error.errorPayload $ Error.PgError False err
|
||||||
|
|
||||||
showListenerError :: Either SomeException () -> Text
|
showOnSingleLine txt = T.intercalate " " $ T.filter (/= '\t') <$> T.lines txt -- the errors from hasql-notifications come intercalated with "\t\n"
|
||||||
showListenerError (Right _) = "Failed getting notifications" -- should not happen as the listener will never finish (hasql-notifications uses `forever` internally) with a Right result
|
|
||||||
showListenerError (Left e) =
|
showListenerConnError :: SQL.ConnectionError -> Text
|
||||||
let showOnSingleLine txt = T.intercalate " " $ T.filter (/= '\t') <$> T.lines txt in -- the errors from hasql-notifications come intercalated with "\t\n"
|
showListenerConnError = maybe "Connection error" (showOnSingleLine . T.decodeUtf8)
|
||||||
showOnSingleLine $ show e
|
|
||||||
|
showListenerException :: Either SomeException () -> Text
|
||||||
|
showListenerException (Right _) = "Failed getting notifications" -- should not happen as the listener will never finish (hasql-notifications uses `forever` internally) with a Right result
|
||||||
|
showListenerException (Left e) = showOnSingleLine $ show e
|
||||||
|
|||||||
@@ -1937,3 +1937,21 @@ def test_schema_cache_error_observation(defaultenv):
|
|||||||
"Failed to load the schema cache using db-schemas=public and db-extra-search-path=x"
|
"Failed to load the schema cache using db-schemas=public and db-extra-search-path=x"
|
||||||
in output[7]
|
in output[7]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_listener_connection_errors(defaultenv):
|
||||||
|
"The logs should show the listener connection error message in a single line"
|
||||||
|
|
||||||
|
env = {
|
||||||
|
**defaultenv,
|
||||||
|
"PGHOST": "no_host",
|
||||||
|
"PGRST_DB_CHANNEL_ENABLED": "true",
|
||||||
|
}
|
||||||
|
|
||||||
|
with run(env=env, no_startup_stdout=False, wait_for_readiness=False) as postgrest:
|
||||||
|
output = postgrest.read_stdout(nlines=5)
|
||||||
|
assert any(
|
||||||
|
'Failed listening for database notifications on the "pgrst" channel. could not translate host name "no_host" to address:'
|
||||||
|
in line
|
||||||
|
for line in output
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user