{"record":{"id":"2aba65e3d2ea7d74","repo":"juanfont/headscale","slug":"building-sqlite-connection-url-w","errorCode":null,"errorMessage":"building sqlite connection URL: %w","messagePattern":"building sqlite connection URL: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hscontrol/db/db.go","lineNumber":1086,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"creating directory for sqlite: %w\", err)\n\t\t}\n\n\t\tlog.Info().\n\t\t\tStr(\"database\", types.DatabaseSqlite).\n\t\t\tStr(\"path\", cfg.Sqlite.Path).\n\t\t\tMsg(\"Opening database\")\n\n\t\t// Build SQLite configuration with pragmas set at connection time\n\t\tsqliteConfig := sqliteconfig.Default(cfg.Sqlite.Path)\n\t\tif cfg.Sqlite.WriteAheadLog {\n\t\t\tsqliteConfig.JournalMode = sqliteconfig.JournalModeWAL\n\t\t\tsqliteConfig.WALAutocheckpoint = cfg.Sqlite.WALAutoCheckPoint\n\t\t}\n\n\t\tconnectionURL, err := sqliteConfig.ToURL()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"building sqlite connection URL: %w\", err)\n\t\t}\n\n\t\tdb, err := gorm.Open(\n\t\t\tsqlite.Open(connectionURL),\n\t\t\t&gorm.Config{\n\t\t\t\tPrepareStmt: cfg.Gorm.PrepareStmt,\n\t\t\t\tLogger:      dbLogger,\n\t\t\t},\n\t\t)\n\n\t\t// The pure Go SQLite library does not handle locking in\n\t\t// the same way as the C based one and we can't use the gorm\n\t\t// connection pool as of 2022/02/23.\n\t\tsqlDB, _ := db.DB()\n\t\tsqlDB.SetMaxIdleConns(1)\n\t\tsqlDB.SetMaxOpenConns(1)\n\t\tsqlDB.SetConnMaxIdleTime(time.Hour)\n","sourceCodeStart":1068,"sourceCodeEnd":1104,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/db/db.go#L1068-L1104","documentation":"headscale serializes its sqlite configuration (pragmas like journal_mode=WAL, wal_autocheckpoint, busy timeout) into a connection URL via sqliteconfig.ToURL(). This error means the assembled configuration could not be rendered into a valid DSN — i.e. some pragma/value combination is unrepresentable.","triggerScenarios":"An invalid or contradictory pragma value in cfg.Sqlite (e.g. a WALAutoCheckPoint value that cannot be encoded, or a path containing characters that break URL encoding). Largely a defensive check; normally unreachable with valid config.","commonSituations":"Manually edited config with out-of-range numeric pragma values; a sqlite path with characters that the URL encoder rejects; version changes to sqliteconfig introducing new required fields left at zero values.","solutions":["Sanitize db.path — use a plain absolute path without unusual characters.","Reset sqlite tuning options (write_ahead_log, wal_autocheckpoint) to defaults and re-add one at a time.","Check the chained error for which pragma failed to encode; fix that config value."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Defensive wrapper only; fix the sqlite config values (path characters,\n// pragma ranges) and re-run. No runtime recovery is meaningful.","preventionTips":["Keep sqlite paths plain absolute paths without special characters.","Leave sqlite tuning options at documented defaults unless tested."],"tags":["database","sqlite","config","dsn"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}