benbjohnson/litestream · error
invalid value for litestream_write_enabled: %s (use 0 or 1)
Error message
invalid value for litestream_write_enabled: %s (use 0 or 1)
What it means
Validation in the litestream_write_enabled PRAGMA handler: the supplied value is not one of 0/false/off or 1/true/on. Fires when a user sets the PRAGMA to an unrecognized string, since write mode is strictly boolean.
Source
Thrown at vfs.go:2525
return &result, nil
}
result := "0"
return &result, nil
}
// WRITE mode - enable or disable
switch strings.ToLower(*pragmaValue) {
case "0", "false", "off":
if err := f.SetWriteEnabled(false); err != nil {
return nil, err
}
return nil, nil
case "1", "true", "on":
if err := f.SetWriteEnabled(true); err != nil {
return nil, err
}
return nil, nil
default:
return nil, fmt.Errorf("invalid value for litestream_write_enabled: %s (use 0 or 1)", *pragmaValue)
}
default:
return nil, sqlite3vfs.NotFoundError
}
}
// currentTimeString returns the current target time as a string.
func (f *VFSFile) currentTimeString() string {
if t := f.TargetTime(); t != nil {
return t.Format(time.RFC3339Nano)
}
if t := f.LatestLTXTime(); !t.IsZero() {
return t.Format(time.RFC3339Nano)
}
return "latest" // Fallback if no LTX files loaded
}
View on GitHub (pinned to 4ed7a308f6)
Solutions
- Use `PRAGMA litestream_write_enabled = 1` to enable writes and `= 0` to disable
- If dynamic, map your boolean to "0"/"1" before building the pragma statement
- Note 'true', 'false', 'on', 'off' are also accepted, case-insensitively
Example fix
// before
conn.Exec("PRAGMA litestream_write_enabled = 'yes'")
// after
conn.Exec("PRAGMA litestream_write_enabled = 1") Defensive patterns
Strategy: validation
Validate before calling
function writeEnabledPragmaValue(v) {
const s = String(v).toLowerCase();
if (!["0","1","true","false","on","off"].includes(s)) throw new Error(`invalid litestream_write_enabled: ${v}`);
return s;
}
// use: `PRAGMA litestream_write_enabled = ${writeEnabledPragmaValue(flag)}` Try / catch
try {
conn.exec(`PRAGMA litestream_write_enabled = ${normalized}`);
} catch (e) {
if (String(e).includes("invalid value for litestream_write_enabled")) {
conn.exec("PRAGMA litestream_write_enabled = 1");
} else throw e;
} Prevention
- Always coerce booleans to "0"/"1" before pragma assignment
- Quote and trim values carefully in shell wrappers
When it happens
Trigger: Executing `PRAGMA litestream_write_enabled = 'yes'` (or any string other than 0/false/off/1/true/on, case-insensitive) on a connection using the Litestream VFS.
Common situations: Typo'd values like 'enabled', 'enable', 'yes', 'no'; locale-formatted booleans; shell quoting issues producing values with trailing whitespace beyond the ToLower-normalized set.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/7ce9212efbec889c.
Report an issue: GitHub.