[GH-ISSUE #14389] BoolWithDefault silently returns true on invalid env var values instead of falling back to default #9350

Open
opened 2026-04-12 22:13:03 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @xidoo123 on GitHub (Feb 24, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/14389

What is the issue?

BoolWithDefault returns true when strconv.ParseBool fails to parse the environment variable value, instead of returning defaultValue. This causes several boolean feature flags to be silently enabled when a user sets an environment variable to a common-but-invalid string like "yes", "on", or "enabled".

func BoolWithDefault(k string) func(defaultValue bool) bool {
	return func(defaultValue bool) bool {
		if s := Var(k); s != "" {
			b, err := strconv.ParseBool(s)
			if err != nil {
				return true  // should be defaultValue
			}

			return b
		}

		return defaultValue
	}
}

strconv.ParseBool only accepts "1", "0", "t", "f", "T", "F", "TRUE", "FALSE", "true", "false", "True", "False". Any other value (including the common "yes", "on", "enabled", "YES") triggers the bug.

Relevant log output


OS

No response

GPU

No response

CPU

No response

Ollama version

No response

Originally created by @xidoo123 on GitHub (Feb 24, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/14389 ### What is the issue? [BoolWithDefault](https://github.com/ollama/ollama/blob/f4f0a4a47119e20a7390007fcafad4ee4984ebac/envconfig/config.go#L159) returns true when strconv.ParseBool fails to parse the environment variable value, instead of returning defaultValue. This causes several boolean feature flags to be silently enabled when a user sets an environment variable to a common-but-invalid string like "yes", "on", or "enabled". ```go func BoolWithDefault(k string) func(defaultValue bool) bool { return func(defaultValue bool) bool { if s := Var(k); s != "" { b, err := strconv.ParseBool(s) if err != nil { return true // should be defaultValue } return b } return defaultValue } } ``` strconv.ParseBool only accepts "1", "0", "t", "f", "T", "F", "TRUE", "FALSE", "true", "false", "True", "False". Any other value (including the common "yes", "on", "enabled", "YES") triggers the bug. ### Relevant log output ```shell ``` ### OS _No response_ ### GPU _No response_ ### CPU _No response_ ### Ollama version _No response_
GiteaMirror added the bug label 2026-04-12 22:13:03 -05:00
Author
Owner

@lingfan36 commented on GitHub (Feb 25, 2026):

👋 Hi there!

We've prepared a detailed solution guide for this issue:

🔗 Solution Guide: https://ollamahub.space/pages/solutions/detail.html?id=configuration/boolwithdefault-env-var-bug

The documentation includes:

  • Problem analysis
  • Workaround solutions
  • Code examples

If your specific case isn't covered, feel free to provide more details.


Generated by OllamaHub

<!-- gh-comment-id:3958040465 --> @lingfan36 commented on GitHub (Feb 25, 2026): 👋 Hi there! We've prepared a detailed solution guide for this issue: 🔗 **Solution Guide**: https://ollamahub.space/pages/solutions/detail.html?id=configuration/boolwithdefault-env-var-bug The documentation includes: - Problem analysis - Workaround solutions - Code examples If your specific case isn't covered, feel free to provide more details. --- *Generated by OllamaHub*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#9350