{"record":{"id":"55650d993fd94eb4","repo":"getgrav/grav","slug":"decoding-yaml-failed-message","errorCode":null,"errorMessage":"Decoding YAML failed: {message}","messagePattern":"Decoding YAML failed: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"system/src/Grav/Framework/File/Formatter/YamlFormatter.php","lineNumber":126,"sourceCode":"            @ini_set('yaml.decode_php', '0');\n            $decoded = @yaml_parse($data);\n            if ($saved !== false) {\n                @ini_set('yaml.decode_php', $saved);\n            }\n\n            if ($decoded !== false) {\n                return (array) $decoded;\n            }\n        }\n\n        try {\n            return (array) YamlParser::parse($data);\n        } catch (ParseException $e) {\n            if ($this->useCompatibleDecoder()) {\n                return (array) FallbackYamlParser::parse($data);\n            }\n\n            throw new RuntimeException('Decoding YAML failed: ' . $e->getMessage(), 0, $e);\n        }\n    }\n}\n","sourceCodeStart":108,"sourceCodeEnd":130,"githubUrl":"https://github.com/getgrav/grav/blob/6040efed04efa69b8209448ed81308e7c24147c2/system/src/Grav/Framework/File/Formatter/YamlFormatter.php#L108-L130","documentation":"YamlFormatter::decode() parses YAML with Symfony Yaml; a ParseException (syntax error in the document) is rethrown as 'Decoding YAML failed', but only after the optional 'compatible' fallback parser also fails or is disabled. It means the file's YAML is syntactically invalid for both the strict parser and (if enabled) the lenient one. The parse error message from Symfony names the exact line and offset.","triggerScenarios":"Loading a page/config file indented with TABs; unquoted values containing ': ' or starting with @ or `; duplicate top-level keys; a UTF-8 BOM at file start; truncated frontmatter after a failed edit or partial upload.","commonSituations":"Hand-editing page frontmatter in an editor that inserts tabs; a deploy pipeline or copy/paste stripping the closing --- delimiter; content authors pasting rich-text (smart quotes, non-breaking spaces) into YAML values.","solutions":["Open the file at the line/column given in the appended ParseException message and fix the syntax (quote the value, fix indentation).","Replace TAB indentation with spaces and remove any BOM (re-save as UTF-8 without BOM).","Validate with a YAML linter (yamllint, or bin/plugin symlinked checks) before deploying.","Enable the compatible decoder ('compatible' => true in formatter options) so minor legacy syntax still parses."],"exampleFix":"# before (page frontmatter, tabs used)\ntitle:\tMy Page\n\n# after\ntitle: \"My Page\"","handlingStrategy":"try-catch","validationCode":"// Pre-flight parse when users edit YAML (e.g. admin save hook)\nuse Grav\\Framework\\File\\Formatter\\YamlFormatter;\ntry {\n    YamlFormatter::parse($raw); // or Symfony Component\\Yaml\\Yaml::parse($raw)\n} catch (\\Symfony\\Component\\Yaml\\Exception\\ParseException $e) {\n    $admin->setMessage('YAML error at line ' . $e->getParsedLine() . ': ' . $e->getSnippet(), 'error');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $data = $formatter->decode($data);\n} catch (\\Grav\\Framework\\File\\Formatter\\Exception\\RuntimeException $e) {\n    // $e->getPrevious() is the ParseException with line/snippet info\n    $line = $e->getPrevious() ? $e->getPrevious()->getParsedLine() : '?';\n    throw new \\RuntimeException(\"{$filename}: invalid YAML near line {$line}\", 0, $e);\n}","preventionTips":["Configure editors to use spaces (never tabs) for YAML indentation.","Save files as UTF-8 without BOM.","Run yamllint in CI over user/config and page frontmatter.","Quote YAML strings that contain colons, @, or leading special characters."],"tags":["yaml","grav","parse-error","frontmatter","symfony-yaml"],"backgroundTag":"yaml-parse-error","analyzedSha":"6040efed04efa69b8209448ed81308e7c24147c2","analyzedAt":"2026-08-17T05:07:31.593Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}