terminal: add db config nil checks

This commit is contained in:
Viktor Torstensson 2026-06-01 21:07:49 +02:00
parent b09fd2852a
commit 93f6aa9e2c
No known key found for this signature in database
GPG key ID: 961CC8259AE675D4

View file

@ -297,6 +297,11 @@ func (c *Config) NewStores(ctx context.Context,
switch c.DatabaseBackend {
case DatabaseBackendSqlite:
if c.Sqlite == nil {
return stores, errors.New("sqlite configuration is " +
"missing")
}
// Before we initialize the SQLite store, we'll make sure that
// the directory where we will store the database file exists.
// Note that the c.Sqlite.DatabaseFileName may already have
@ -349,6 +354,11 @@ func (c *Config) NewStores(ctx context.Context,
stores.firewall = firewalldb.NewDB(firewallStore)
case DatabaseBackendPostgres:
if c.Postgres == nil {
return stores, errors.New("postgres configuration is " +
"missing")
}
sqlStore, err := sqldb.NewPostgresStore(&sqldb.PostgresConfig{
Dsn: c.Postgres.DSN(false),
MaxOpenConnections: c.Postgres.MaxOpenConnections,
@ -698,7 +708,9 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
// final LiT directory and network. This keeps the default aligned
// with any user overrides that changed lit-dir or network during
// config loading.
if cfg.Sqlite.DatabaseFileName == defaultSqliteDatabasePath {
if cfg.Sqlite != nil &&
cfg.Sqlite.DatabaseFileName == defaultSqliteDatabasePath {
cfg.Sqlite.DatabaseFileName = filepath.Join(
litDir, cfg.Network, defaultSqliteDatabaseFileName,
)