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 = b

View on GitHub (pinned to 14bfc25627)

Solutions

  1. Set the env var to a plain base-10 integer (e.g. PORT=8080, TIMEOUT=30).
  2. Strip surrounding whitespace/quotes from the value or from the _FILE contents.
  3. Convert duration/unit values to their integer form before assigning the env var.
  4. 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

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


AI-assisted analysis of gotify/server@14bfc25627 (2026-09-05). Data as JSON: /api/errors/1a58ac557b90eb5e. Report an issue: GitHub.