getgrav/grav · error · RuntimeException

Decoding INI failed

Error message

Decoding INI failed

What it means

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.

Source

Thrown at system/src/Grav/Framework/File/Formatter/IniFormatter.php:63

                ['/"/', '/\\\/', "/\t/", "/\n/", "/\r/"],
                ['\"',  '\\\\', '\t',   '\n',   '\r'],
                (string) $value
            ) . "\"\n";
        }

        return $string;
    }

    /**
     * {@inheritdoc}
     * @see FileFormatterInterface::decode()
     */
    public function decode($data): array
    {
        $decoded = @parse_ini_string($data);

        if ($decoded === false) {
            throw new RuntimeException('Decoding INI failed');
        }

        return $decoded;
    }
}

View on GitHub (pinned to 6040efed04)

Solutions

  1. Bisect the file: run parse_ini_string on halves to isolate the failing line, then fix the syntax.
  2. Quote values that contain special characters: key = "a | b".
  3. Confirm the file really is INI — check the extension-to-formatter mapping if another format was intended.
  4. Test in isolation: php -r 'var_dump(parse_ini_string(file_get_contents("f.ini")));'

Example fix

; before
menu = Custom | Main

; after
menu = "Custom | Main"
Defensive patterns

Strategy: try-catch

Validate before calling

// Cheap pre-check: the same call the formatter makes
if (@parse_ini_string($data) === false) {
    // fix the INI syntax before calling IniFormatter::decode()
}

Try / catch

try {
    $data = $iniFormatter->decode($data);
} catch (\RuntimeException $e) {
    $log->error('INI parse failed: ' . $e->getMessage());
    $data = $defaults;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of getgrav/grav@6040efed04 (2026-08-17). Data as JSON: /api/errors/92744ffd33e5120a. Report an issue: GitHub.