# Does Postgres-Nio not report errors?

**URL:** <https://forums.swift.org/t/does-postgres-nio-not-report-errors/81013>\
**Category:** Using Swift\
**Tags:** postgres-nio\
**Created:** [July 9, 2025, 12:37pm UTC](https://forums.swift.org/t/does-postgres-nio-not-report-errors/81013 "2025-07-09T12:37:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Q-Bert](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/q-bert/32/19862_2.png) [@Q-Bert](https://forums.swift.org/u/Q-Bert)\
**Post date:** [July 9, 2025, 12:37pm UTC](https://forums.swift.org/t/does-postgres-nio-not-report-errors/81013/1 "2025-07-09T12:37:40Z")

</div>

**Note:** Not sure if this is the correct venue (or category) for my questions.

It feels like I am missing something!! How can the following [postgres-nio](https://github.com/vapor/postgres-nio) API calls claim to _never_ fail? Notice the lack of error reporting mechanism: no failable `init?()`, no `throws`, no `Result<>`, etc.

```swift
let client = PostgresClient(configuration: …)
await withTaskGroup(of: Void.self) { taskGroup in
    defer {
        // To shutdown the client, cancel its run method, by cancelling the taskGroup.
        taskGroup.cancelAll()
    }
    taskGroup.addTask {
        await client.run()
        // ⚠️ This hangs — awaits forever — if ever we can't connect to DB for **ANY** reason.
        // I.e. host doesn't answer or wrong credentials
    }
    // … interact with DB here …
}

```

1. Why doesn't it honour the `PostgresClient.options.connectTimeout` instead of waiting forever?
2. `PostgresClient.run()` does not throw, nor does it return a value to indicate an error; How would you obtain any useful error information?

Even _ **if** _ someone were to claim "it's not postgres-nio's responsibility; it's yours!"… if I were to implement my own timeout detection… how would I ever report anything that's useful?! I wouldn't know if it's the database that's not reachable, or wrong credentials, etc.

This doesn't seem suitable for any production projects. I must be missing something, right?!

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [July 9, 2025, 3:15pm UTC](https://forums.swift.org/t/does-postgres-nio-not-report-errors/81013/2 "2025-07-09T15:15:29Z")

</div>

Starting the client (by calling `.run()`) doesn't actually _do_ anything that talks to the server - it starts the client, sets up the connection pool ready to hold connections etc. It isn't until you make an actual query with `.query()` etc that it will attempt to reach out to the server and where the timeout will come into effect.

And yes, it's most definitely used in production at very large scale

---

<div class="post-metadata">

**Author:** ![Q-Bert](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/q-bert/32/19862_2.png) [@Q-Bert](https://forums.swift.org/u/Q-Bert)\
**Post date:** [July 9, 2025, 4:07pm UTC](https://forums.swift.org/t/does-postgres-nio-not-report-errors/81013/3 "2025-07-09T16:07:25Z")

</div>

@0xTim If that is so, why must I specify a time limit to the following `@Test()` for it to end?!

```swift
    @Test("Postgres Connection!", .timeLimit(.minutes(5)))
    func postgresNio() async throws {
        let config = PostgresClient.Configuration( … )
        let client = PostgresClient(configuration: config, backgroundLogger: logger)
        await withThrowingTaskGroup(of: Void.self) { taskGroup in
            defer {
                taskGroup.cancelAll()
            }
            taskGroup.addTask {
                 await client.run()
            }

            try await client.query("Select nothing from nonExistingTable", logger: logger)
        }
    }

```

I would expect the test to throw an error and end once the `PostgresClient.options.connectTimeout` (default of 10s) has elapsed. Wouldn't `try await client.query()` throw once the 10s timeout is done and fire the defered block to `cancelAll()` tasks?!

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [July 9, 2025, 6:38pm UTC](https://forums.swift.org/t/does-postgres-nio-not-report-errors/81013/4 "2025-07-09T18:38:08Z")

</div>

My guess here without looking into it is that's a bug in the library because the query call is happening before the client is set up (because the `client.run()` is inside the `addTask` block whereas the query call is invoked immediately. That should probably throw an error because you're trying to use the client before it was started. I suspect if you ensure the client is set up first it should fail as expected

---

<div class="post-metadata">

**Author:** ![Q-Bert](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/q-bert/32/19862_2.png) [@Q-Bert](https://forums.swift.org/u/Q-Bert)\
**Post date:** [July 10, 2025, 11:27pm UTC](https://forums.swift.org/t/does-postgres-nio-not-report-errors/81013/5 "2025-07-10T23:27:22Z")

</div>

Thank you @0xTim! Just wanted to close this with a bit of feedback…

Everything above seems to have spawned from my lack of understanding of `ThrowingTaskGroup`'s [`next()`](https://developer.apple.com/documentation/swift/throwingtaskgroup/next()) which has, in my opinion, too little documentation — one has to _ **assume** _ it does the same as `nextResult(isolation:)` and we know where assumptions lead us — nor have I seen examples/articles of others using it.

I only now just recently managed to find [Error-Handling `withThrowingTaskGroup()`](https://developer.apple.com/documentation/swift/withthrowingtaskgroup(of:returning:isolation:body:)#Error-Handling) so I have some reading and experimentation to do.
