{"record":{"id":"92744ffd33e5120a","repo":"getgrav/grav","slug":"decoding-ini-failed","errorCode":null,"errorMessage":"Decoding INI failed","messagePattern":"Decoding INI failed","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"system/src/Grav/Framework/File/Formatter/IniFormatter.php","lineNumber":63,"sourceCode":"                ['/\"/', '/\\\\\\/', \"/\\t/\", \"/\\n/\", \"/\\r/\"],\n                ['\\\"',  '\\\\\\\\', '\\t',   '\\n',   '\\r'],\n                (string) $value\n            ) . \"\\\"\\n\";\n        }\n\n        return $string;\n    }\n\n    /**\n     * {@inheritdoc}\n     * @see FileFormatterInterface::decode()\n     */\n    public function decode($data): array\n    {\n        $decoded = @parse_ini_string($data);\n\n        if ($decoded === false) {\n            throw new RuntimeException('Decoding INI failed');\n        }\n\n        return $decoded;\n    }\n}\n","sourceCodeStart":45,"sourceCodeEnd":69,"githubUrl":"https://github.com/getgrav/grav/blob/6040efed04efa69b8209448ed81308e7c24147c2/system/src/Grav/Framework/File/Formatter/IniFormatter.php#L45-L69","documentation":"IniFormatter::decode() runs @parse_ini_string($data) and throws when it returns false, meaning the payload is not valid INI: a syntax error (missing '=', stray characters), reserved characters in unquoted values, malformed section headers, or content that is not INI at all mapped to this formatter by its file extension.","triggerScenarios":"Decoding a .ini file with a malformed line; unquoted values containing reserved characters ({}|&~!()^\"); a file whose extension routes it to IniFormatter although it holds YAML/JSON; keys written with invalid syntax for the active scanner mode.","commonSituations":"Hand-edited INI configuration; values copied from docs with typographic quotes; assigning plugin config values that contain special characters; format/extension mismatch after renaming files.","solutions":["Bisect the file: run parse_ini_string on halves to isolate the failing line, then fix the syntax.","Quote values that contain special characters: key = \"a | b\".","Confirm the file really is INI — check the extension-to-formatter mapping if another format was intended.","Test in isolation: php -r 'var_dump(parse_ini_string(file_get_contents(\"f.ini\")));'"],"exampleFix":"; before\nmenu = Custom | Main\n\n; after\nmenu = \"Custom | Main\"","handlingStrategy":"try-catch","validationCode":"// Cheap pre-check: the same call the formatter makes\nif (@parse_ini_string($data) === false) {\n    // fix the INI syntax before calling IniFormatter::decode()\n}","typeGuard":null,"tryCatchPattern":"try {\n    $data = $iniFormatter->decode($data);\n} catch (\\RuntimeException $e) {\n    $log->error('INI parse failed: ' . $e->getMessage());\n    $data = $defaults;\n}","preventionTips":["Quote INI values containing special characters.","Prefer YAML/JSON for new configuration; reserve INI for legacy interop.","Validate INI files in CI with parse_ini_string."],"tags":["php","grav","ini","parse-error","config"],"backgroundTag":"ini-parse-error","analyzedSha":"6040efed04efa69b8209448ed81308e7c24147c2","analyzedAt":"2026-08-17T05:07:31.593Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}