sosedoff / pgweb

Cross-platform client for PostgreSQL databases
https://sosedoff.github.io/pgweb
MIT License
8.47k stars 716 forks source link

Panic if PGSERVICEFILE set on environment #736

Closed ddevienne closed 1 month ago

ddevienne commented 2 months ago

A little harsh, and not the best first impression for new users. Having LIBPQ standard env-var should be a pretty common occurrence for users of PostgreSQL. Perhaps just a warning that this env-var is ignored and go on would be better, no? Also, there are 30+ env-vars used by LIBPQ (and new releases add some once in a while), so why single out that one?

Thanks, --DD

E:\github\sosedoff\pgweb>.\pgweb_windows_amd64.exe
Pgweb v0.15.0 (git: 9717d3a13273e2cbec1eff6745135d58ba434fd4) (go: go1.21.5) (build time: 2024-03-15T05:23:00Z) (arch: windows/amd64)
panic: setting PGSERVICEFILE not supported

goroutine 1 [running]:
github.com/lib/pq.parseEnviron.func2(...)
        /Users/sosedoff/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:1985
github.com/lib/pq.parseEnviron({0xc000695500, 0x48, 0x16202dc?})
        /Users/sosedoff/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:2008 +0xbcb
github.com/lib/pq.NewConnector({0xc000688600, 0x56})
        /Users/sosedoff/go/pkg/mod/github.com/lib/pq@v1.10.5/connector.go:56 +0x10a
github.com/lib/pq.DialOpen({0x18aded8?, 0xc00027a460}, {0xc000688600?, 0xc00053d0d0?})
        /Users/sosedoff/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:321 +0x31
github.com/lib/pq.Open(...)
        /Users/sosedoff/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:316
github.com/lib/pq.Driver.Open({}, {0xc000688600, 0x56})
        /Users/sosedoff/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:54 +0x85
database/sql.dsnConnector.Connect(...)
        /opt/homebrew/Cellar/go/1.21.5/libexec/src/database/sql/sql.go:758
database/sql.(*DB).conn(0xc000040f70, {0x18b06f0, 0xc00027a3f0}, 0x1)
        /opt/homebrew/Cellar/go/1.21.5/libexec/src/database/sql/sql.go:1387 +0x717
database/sql.(*DB).query(0x10?, {0x18b06f0, 0xc00027a3f0}, {0x161db93, 0x10}, {0x0, 0x0, 0x0}, 0x0?)
        /opt/homebrew/Cellar/go/1.21.5/libexec/src/database/sql/sql.go:1721 +0x57
database/sql.(*DB).QueryContext.func1(0x1?)
        /opt/homebrew/Cellar/go/1.21.5/libexec/src/database/sql/sql.go:1704 +0x4f
database/sql.(*DB).retry(0x0?, 0xc00053d448)
        /opt/homebrew/Cellar/go/1.21.5/libexec/src/database/sql/sql.go:1538 +0x42
database/sql.(*DB).QueryContext(0x1dbc380?, {0x18b06f0?, 0xc00027a3f0?}, {0x161db93?, 0x0?}, {0x0?, 0x66435b01?, 0x12ce808?})
        /opt/homebrew/Cellar/go/1.21.5/libexec/src/database/sql/sql.go:1703 +0xc5
github.com/jmoiron/sqlx.(*DB).QueryxContext(0xc00032b920, {0x18b06f0?, 0xc00027a3f0?}, {0x161db93?, 0x0?}, {0x0?, 0xe?, 0x164b966?})
        /Users/sosedoff/go/pkg/mod/github.com/jmoiron/sqlx@v1.3.5/sqlx_context.go:161 +0x3c
github.com/sosedoff/pgweb/pkg/client.(*Client).query(0xc0001fa780, {0x161db93, 0x10}, {0x0, 0x0, 0x0})
        /Users/sosedoff/go/src/github.com/sosedoff/pgweb/pkg/client/client.go:509 +0x3b0
github.com/sosedoff/pgweb/pkg/client.(*Client).setServerVersion(0xc0001fa780)
        /Users/sosedoff/go/src/github.com/sosedoff/pgweb/pkg/client/client.go:191 +0x2f
github.com/sosedoff/pgweb/pkg/client.(*Client).init(...)
        /Users/sosedoff/go/src/github.com/sosedoff/pgweb/pkg/client/client.go:187
github.com/sosedoff/pgweb/pkg/client.New()
        /Users/sosedoff/go/src/github.com/sosedoff/pgweb/pkg/client/client.go:81 +0x235
github.com/sosedoff/pgweb/pkg/cli.initClient()
        /Users/sosedoff/go/src/github.com/sosedoff/pgweb/pkg/cli/cli.go:69 +0xae
github.com/sosedoff/pgweb/pkg/cli.Run()
        /Users/sosedoff/go/src/github.com/sosedoff/pgweb/pkg/cli/cli.go:299 +0x33
main.main()
        /Users/sosedoff/go/src/github.com/sosedoff/pgweb/main.go:8 +0xf
sosedoff commented 1 month ago

The panic error you're seeing is coming from Pgweb's dependency (lib/pq), you can see this on the line /Users/sosedoff/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:1985. Not much i can do about it.

ddevienne commented 1 month ago

[...] Not much i can do about it.

Darn, 0 for 2. You could maybe unsetenv and warn; or test and fail gracefully perhaps, before lib/pq panics. I just wasn't expecting Go-native PostgreSQL support to be kinda hostile to native libpq users (which includes psql of course). Anyways, thanks for your time. Work-around exists, end user can unsetenv herself, it's just not beginner friendly, that's my point.