glanceapp/glance · error
readFileFromEnv: environment variable %s not found
Error message
readFileFromEnv: environment variable %s not found
What it means
Thrown by parseConfigVariableOfType for {{ file-from-env.NAME }} expressions: NAME is looked up as an environment variable whose VALUE is a file path, and this error means NAME itself is not set in the environment. It is the env-lookup stage of the two-step indirection (env var → path → read file).
Source
Thrown at internal/glance/config.go:218
}
return v, false, nil
case configVarTypeSecret:
secretPath := filepath.Join("/run/secrets", variableName)
secret, err := os.ReadFile(secretPath)
if err != nil {
return "", false, fmt.Errorf("reading secret file: %v", err)
}
return strings.TrimSpace(string(secret)), false, nil
case configVarTypeFileFromEnv:
if !envVariableNamePattern.MatchString(variableName) {
return "", true, nil
}
filePath, found := os.LookupEnv(variableName)
if !found {
return "", false, fmt.Errorf("readFileFromEnv: environment variable %s not found", variableName)
}
if !filepath.IsAbs(filePath) {
return "", false, fmt.Errorf("readFileFromEnv: file path %s is not absolute", filePath)
}
fileContents, err := os.ReadFile(filePath)
if err != nil {
return "", false, fmt.Errorf("readFileFromEnv: reading file from %s: %v", variableName, err)
}
return strings.TrimSpace(string(fileContents)), false, nil
default:
return "", true, nil
}
}
func formatWidgetInitError(err error, w widget) error {View on GitHub (pinned to 91324e8de7)
Solutions
- Export the environment variable pointing at the file: `export API_KEY_FILE=/etc/glance/api_key`.
- Add it to the systemd unit Environment=, docker-compose environment:, or the container env.
- Verify spelling/case of the variable name in {{ file-from-env.X }}.
- Confirm the variable is set for the service user, not just your login shell (`systemctl show-environment`, `docker exec env`).
Example fix
# systemd unit (before) [Service] ExecStart=/usr/bin/glance --config /etc/glance/glance.yml # after [Service] Environment=API_KEY_FILE=/etc/glance/api_key ExecStart=/usr/bin/glance --config /etc/glance/glance.yml
Defensive patterns
Strategy: validation
Validate before calling
for var in $(grep -oE '\{\{ *file-from-env\.[A-Za-z_][A-Za-z0-9_]* *\}\}' glance.yml | sed -E 's/.*file-from-env\.([A-Za-z0-9_]+).*/\1/'); do
printenv "$var" >/dev/null || { echo "file-from-env variable not set: $var"; exit 1; }
done Prevention
- Treat *_FILE variables as required service configuration; declare them in the unit/compose file.
- Verify with `docker exec <ctr> env | grep _FILE=` that the indirection variable actually reached the process.
When it happens
Trigger: glance.yml contains {{ file-from-env.API_KEY_FILE }} and API_KEY_FILE is unset in the Glance process environment, even if the target file exists on disk.
Common situations: Using the file-from-env indirection for secret files at custom paths but forgetting to export the *_FILE variable in systemd/docker; env var set in the interactive shell but not in the service unit; typo in the variable name.
Related errors
- parsing variable: %v
- environment variable %s not found
- readFileFromEnv: reading file from %s: %v
- reading secret file: %v
- readFileFromEnv: file path %s is not absolute
AI-assisted analysis of glanceapp/glance@91324e8de7 (2026-08-15).
Data as JSON: /api/errors/11877c8498249e32.
Report an issue: GitHub.