gotify/server · error
invalid int for %s (%q): %w
Error message
invalid int for %s (%q): %w
What it means
parseInt reads the env var (directly or via _FILE) and converts it with strconv.Atoi. Any value that is not a plain decimal integer produces 'invalid int for %s (%q): %w', naming the variable, the offending raw value, and the underlying strconv error.
Source
Thrown at config/parse.go:48
return err
}
if ok {
*target = raw
}
return nil
}
func parseInt(target *int, env string) error {
raw, ok, err := lookupEnv(env)
if err != nil {
return err
}
if !ok {
return nil
}
n, err := strconv.Atoi(raw)
if err != nil {
return fmt.Errorf("invalid int for %s (%q): %w", env, raw, err)
}
*target = n
return nil
}
func parseBool(target *bool, env string) error {
raw, ok, err := lookupEnv(env)
if err != nil {
return err
}
if !ok {
return nil
}
b, err := strconv.ParseBool(raw)
if err != nil {
return fmt.Errorf("invalid bool for %s (%q): %w", env, raw, err)
}
*target = bView on GitHub (pinned to 14bfc25627)
Solutions
- Set the env var to a plain base-10 integer (e.g. PORT=8080, TIMEOUT=30).
- Strip surrounding whitespace/quotes from the value or from the _FILE contents.
- Convert duration/unit values to their integer form before assigning the env var.
- Log the %q-quoted raw value from the error to spot invisible characters, then fix the deployment config.
Example fix
// before PORT=8080ms // after PORT=8080
Defensive patterns
Strategy: validation
Validate before calling
func assertIntEnv(env string) error {
raw := os.Getenv(env)
if raw == "" { return nil }
if _, err := strconv.Atoi(strings.TrimSpace(raw)); err != nil {
return fmt.Errorf("%s=%q is not an integer", env, raw)
}
return nil
}
// assertIntEnv("PORT") before config.Get Try / catch
if err := config.Get(&cfg); err != nil {
var perr *strconv.NumError
if strings.Contains(err.Error(), "invalid int for") {
return fmt.Errorf("fix the integer env var in your deployment: %w", err)
}
_ = perr
return err
} Prevention
- Set integer env vars as bare base-10 numbers; no units, separators, or quotes
- Strip whitespace when writing _FILE secrets (printf, not echo with padding)
- Validate all env vars in CI with a startup smoke test
- Read the %q raw value in the error to catch invisible characters
When it happens
Trigger: Calling config.Get with an integer-typed setting whose env value is empty, contains spaces, uses underscores or thousands separators ('1_000'), has a unit suffix ('8080ms', '5GB'), or is a quoted string from a _FILE with a trailing newline that survived if only \r\n were expected... (note lookupEnv trims \r\n; other whitespace remains).
Common situations: Setting PORT to 'localhost:8080' instead of a number, timeouts written as '30s' instead of an int, secrets files with extra whitespace, or pasting values with surrounding quotes.
Related errors
- invalid bool for %s (%q): %w
- invalid CSV for %s (%q): %w
- read file for %s_FILE (%s): %w
- cannot parse config file %s: %w
- cannot delete internal application
AI-assisted analysis of gotify/server@14bfc25627 (2026-09-05).
Data as JSON: /api/errors/1a58ac557b90eb5e.
Report an issue: GitHub.