{"record":{"id":"3678715c83b071b8","repo":"docker/compose","slug":"failed-to-parse-env-file-s-w","errorCode":null,"errorMessage":"failed to parse env_file %s: %w","messagePattern":"failed to parse env_file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/compose.go","lineNumber":79,"sourceCode":"\t// ComposeCompatibility try to mimic compose v1 as much as possible\n\tComposeCompatibility = api.ComposeCompatibility\n\t// ComposeRemoveOrphans remove \"orphaned\" containers, i.e. containers tagged for current project but not declared as service\n\tComposeRemoveOrphans = \"COMPOSE_REMOVE_ORPHANS\"\n\t// ComposeIgnoreOrphans ignore \"orphaned\" containers\n\tComposeIgnoreOrphans = \"COMPOSE_IGNORE_ORPHANS\"\n\t// ComposeEnvFiles defines the env files to use if --env-file isn't used\n\tComposeEnvFiles = \"COMPOSE_ENV_FILES\"\n\t// ComposeMenu defines if the navigation menu should be rendered. Can be also set via --menu\n\tComposeMenu = \"COMPOSE_MENU\"\n\t// ComposeProgress defines type of progress output, if --progress isn't used\n\tComposeProgress = \"COMPOSE_PROGRESS\"\n)\n\n// rawEnv load a dot env file using docker/cli key=value parser, without attempt to interpolate or evaluate values\nfunc rawEnv(r io.Reader, filename string, vars map[string]string, lookup func(key string) (string, bool)) error {\n\tlines, err := kvfile.ParseFromReader(r, lookup)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to parse env_file %s: %w\", filename, err)\n\t}\n\tfor _, line := range lines {\n\t\tkey, value, _ := strings.Cut(line, \"=\")\n\t\tvars[key] = value\n\t}\n\treturn nil\n}\n\nvar stdioToStdout bool\n\nfunc init() {\n\t// compose evaluates env file values for interpolation\n\t// `raw` format allows to load env_file with the same parser used by docker run --env-file\n\tdotenv.RegisterFormat(\"raw\", rawEnv)\n\n\tif v, ok := os.LookupEnv(\"COMPOSE_STATUS_STDOUT\"); ok {\n\t\tstdioToStdout, _ = strconv.ParseBool(v)\n\t}","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/compose.go#L61-L97","documentation":"When compose reads an env_file (--env-file, or the command-level env-file handling that uses rawEnv), it parses it with docker/cli's key=value parser. Any line that does not conform (unterminated quote, invalid shell-ish syntax, BOM/encoding issues) makes ParseFromReader fail, and rawEnv wraps the failure with the offending file name.","triggerScenarios":"Passing --env-file .env.crashed with a malformed line (e.g. VALUE=\"unterminated, stray backslash, or a line without '='), or a file saved with CRLF/BOM or non-UTF8 bytes.","commonSituations":"Windows-edited env files with CRLF or smart quotes; a missing closing quote after editing values with spaces; secrets injected into env files breaking quoting; empty lines are fine but lines like `export FOO=bar` (the export prefix) can trip strict parsers depending on version.","solutions":["Open the named file at the reported path and fix the malformed line (usually an unterminated quote or a line missing '=')","Normalize the file: UTF-8, LF endings, KEY=VALUE per line, quote values containing spaces symmetrically","Validate quickly: `docker run --rm -v $PWD:/w alpine sh -c 'set -a; . /w/.env'` or a linter such as dotenv-linter","If the file is generated, ensure the generator escapes quotes/newlines correctly"],"exampleFix":"# before (.env)\nAPP_ARGS=\"--foo bar      # unterminated quote\n# after (.env)\nAPP_ARGS=\"--foo bar\"\n","handlingStrategy":"validation","validationCode":"python3 - <<'EOF'\nimport sys\nfor fn in sys.argv[1:]:\n    for i,l in enumerate(open(fn, encoding='utf-8'), 1):\n        s=l.strip()\n        if not s or s.startswith('#'): continue\n        if '\"' in s and s.count('\"') % 2: sys.exit(f\"{fn}:{i} unbalanced quote\")\n        if '=' not in s: sys.exit(f\"{fn}:{i} missing =\")\nprint('env files ok')\nEOF .env","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run dotenv-linter over env files in CI","Save env files as UTF-8 with LF endings; avoid smart quotes from word processors"],"tags":["env-file","parsing","configuration"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}