fyne-io/fyne · error
malformed env var %q from input
Error message
malformed env var %q from input
What it means
environ(kv) merges the process environment with caller-supplied KEY=VALUE strings used for the gomobile build env (CC, CGO_CFLAGS, GOARM, ...). Entries coming from os.Environ of unusual form are passed through untouched, but every kv entry is treated as trusted input and must contain '=' with a non-empty key; anything else panics so it cannot silently corrupt the child build environment.
Source
Thrown at cmd/fyne/internal/mobile/env.go:315
envs := make(map[string]string, len(cur))
for _, ev := range cur {
elem := strings.SplitN(ev, "=", 2)
if len(elem) != 2 || elem[0] == "" {
// pass the env var of unusual form untouched.
// e.g. Windows may have env var names starting with "=".
new = append(new, ev)
continue
}
if goos == "windows" {
elem[0] = strings.ToUpper(elem[0])
}
envs[elem[0]] = elem[1]
}
for _, ev := range kv {
elem := strings.SplitN(ev, "=", 2)
if len(elem) != 2 || elem[0] == "" {
panic(fmt.Sprintf("malformed env var %q from input", ev))
}
if goos == "windows" {
elem[0] = strings.ToUpper(elem[0])
}
envs[elem[0]] = elem[1]
}
for k, v := range envs {
new = append(new, k+"="+v)
}
return new
}
func archNDK() string {
if runtime.GOOS == "windows" && runtime.GOARCH == "386" {
return "windows"
}
var arch stringView on GitHub (pinned to 8860ee95c3)
Solutions
- Fix the offending entry to KEY=VALUE form - the panic message prints the exact malformed string
- Filter the slice before passing it: drop empty strings and entries without '=' or with an empty key
- Audit env/CI files for stray newlines or quotes feeding the build script
Example fix
// before
kv := []string{"CGO_CFLAGS", "CGO_ENABLED=1"}
// after
kv := []string{"CGO_CFLAGS=-O2", "CGO_ENABLED=1"} Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight: sanitize env pairs before passing them to the build environment.
func sanitizeEnv(kv []string) ([]string, error) {
out := make([]string, 0, len(kv))
for _, ev := range kv {
if ev == "" { continue }
k, v, ok := strings.Cut(ev, "=")
if !ok || k == "" { return nil, fmt.Errorf("malformed env var %q", ev) }
out = append(out, k+"="+v)
}
return out, nil
} Prevention
- Build env lists with explicit key=value constants, not string concatenation
- Trim whitespace/newlines when parsing env files into slices
- Unit-test your env assembly helper for entries missing '='
When it happens
Trigger: Passing an env slice containing an entry without '=' (e.g. 'CGO_CFLAGS') or with an empty name (e.g. '=foo') into environ - usually via custom build scripts or CI that assembles the variable list by string concatenation.
Common situations: Env lists built by concatenation where a value or '=' was dropped; env files with trailing newlines splitting 'A=b' into 'A=b' plus a fragment; CI matrix variables with missing separators.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- unimplemented; GOOS/CGO combination not supported
- out of touchIDs
- unhandled token type: %T %+v
- encountered empty values slice
- TODO only know how to handle DataIntDec type here
AI-assisted analysis of fyne-io/fyne@8860ee95c3 (2026-08-15).
Data as JSON: /api/errors/b95a5c3517319a22.
Report an issue: GitHub.