forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show non-PgError errors when connecting to db (flyteorg#445)
Signed-off-by: Sam Lai <[email protected]> When connecting to a database instance that doesn't exist, that error is currently masked due to an invalid assumption that all wrapped errors returned from gorm are of type `*pgconn.PgError`. When a network error occurs, the returned error is of type `*net.OpError`. This causes the following panic - ``` {"json":{"src":"base.go:73"},"level":"fatal","msg":"caught panic: interface conversion: error is *net.OpError, not *pgconn.PgError [goroutine 1 [running]:\nruntime/debug.Stack()\n\t/home/user/.local/go/src/runtime/debug/stack.go:24 ... ``` ... and doesn't show what the actual error is. This PR fixes that by using the functions in the `errors` package to check if the error chain contains an error of type `*pgconn.PgError`, and if not, simply returns the error. It also removes the ConnectError interface, as it is no longer needed - the `errors.As` function will automatically check the whole error chain and unwrap as necessary. With this fix, the error becomes - ``` {"json":{"src":"base.go:82"},"level":"fatal","msg":"failed to connect to `host=localhost user=postgres database=flyte`: dial error (dial tcp 127.0.0.1:5432: connect: connection refused)","ts":"2022-06-11T20:48:28+01:00"} ```
- Loading branch information
Showing
3 changed files
with
67 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters