gotify/server · error

invalid bool for %s (%q): %w

Error message

invalid bool for %s (%q): %w

What it means

parseBool reads the env var and converts it with strconv.ParseBool, which only accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Anything else (yes, on, enabled, empty) yields 'invalid bool for %s (%q): %w'.

Source

Thrown at config/parse.go:64

	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
	return nil
}

func parseList(target *[]string, env string) error {
	raw, ok, err := lookupEnv(env)
	if err != nil {
		return err
	}
	if !ok {
		return nil
	}
	if raw == "" {
		*target = []string{}
		return nil
	}
	reader := csv.NewReader(strings.NewReader(raw))

View on GitHub (pinned to 14bfc25627)

Solutions

  1. Change the value to one strconv.ParseBool accepts: true/false, 1/0, t/f, TRUE/FALSE.
  2. Strip quotes and whitespace from the value (DEBUG="true" in a shell keeps the quotes).
  3. If you need yes/no semantics, transform them before config load or change the config schema to a string flag.
  4. Read the %q raw value in the error to identify invisible characters, then correct the environment definition.

Example fix

// before
DEBUG=yes
// after
DEBUG=true
Defensive patterns

Strategy: validation

Validate before calling

func assertBoolEnv(env string) error {
    raw := os.Getenv(env)
    if raw == "" { return nil }
    if _, err := strconv.ParseBool(strings.TrimSpace(raw)); err != nil {
        return fmt.Errorf("%s=%q is not a Go bool (use true/false/1/0)", env, raw)
    }
    return nil
}

Try / catch

if err := config.Get(&cfg); err != nil {
    if strings.Contains(err.Error(), "invalid bool for") {
        return fmt.Errorf("boolean env vars must be true/false/1/0: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling config.Get with a boolean-typed setting whose env value is 'yes'/'no', 'on'/'off', 'Y'/'N', 'enabled', an empty string, or a value with trailing whitespace or quotes.

Common situations: Developers using shell-style truthy values (DEBUG=yes), CI variables set to 'ON', a _FILE containing a value with a trailing space, or toggles left empty.

Related errors


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