From 2ec6cbdde89e90b9b5536f091cbb3756f24a2bec Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Fri, 2 Oct 2026 09:47:13 +0800 Subject: [PATCH] =?UTF-8?q?fix=F0=9F=90=9B:=20tell=20a=20default=20build?= =?UTF-8?q?=20how=20to=20get=20the=20sqlite3=20driver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A default build does not include sqlite3, and a config that names it stopped with "unsupported database driver "sqlite3", this build supports mysql, postgres, sqlserver". That says what is missing but not what to do about it. For sqlite3 specifically, say to rebuild with -tags sqlite3. The test runs only in a build without the tag, and fails without the hint. --- common/database/driver.go | 6 ++++++ common/database/driver_nosqlite_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 common/database/driver_nosqlite_test.go diff --git a/common/database/driver.go b/common/database/driver.go index eac8340c..e8184f59 100644 --- a/common/database/driver.go +++ b/common/database/driver.go @@ -17,6 +17,12 @@ import ( func openerFor(driver string) (func(string) gorm.Dialector, error) { open, ok := opens[driver] if !ok { + // sqlite3 is the driver people reach for first, and the one a default + // build leaves out. Say how to get it rather than only what is missing. + if driver == "sqlite3" { + return nil, fmt.Errorf("database driver %q is not in this build, rebuild with -tags sqlite3 (this build supports %s)", + driver, strings.Join(supportedDrivers(), ", ")) + } return nil, fmt.Errorf("unsupported database driver %q, this build supports %s", driver, strings.Join(supportedDrivers(), ", ")) } diff --git a/common/database/driver_nosqlite_test.go b/common/database/driver_nosqlite_test.go new file mode 100644 index 00000000..2d14d52f --- /dev/null +++ b/common/database/driver_nosqlite_test.go @@ -0,0 +1,20 @@ +//go:build !sqlite3 + +package database + +import ( + "strings" + "testing" +) + +// A default build has no sqlite3, and a config naming it is the usual first +// run. The error has to say how to get the driver, not only that it is missing. +func TestOpenerForTellsHowToGetSqliteInADefaultBuild(t *testing.T) { + _, err := openerFor("sqlite3") + if err == nil { + t.Fatal("sqlite3 was accepted by a build without the sqlite3 tag") + } + if !strings.Contains(err.Error(), "-tags sqlite3") { + t.Errorf("error does not say how to enable sqlite3: %s", err) + } +}