stride3d/stride · error · SyntaxErrorException
While scanning a %YAML directive, did not find expected…
Error message
While scanning a %YAML directive, did not find expected version number.
What it means
Scanner.ScanVersionDirectiveValue finished reading a %YAML directive component but consumed zero digits, meaning the expected major or minor version number is missing. Since a %YAML directive requires 'major.minor', the scanner throws SyntaxErrorException.
Solutions
- Write a complete version: '%YAML 1.1' (or 1.2).
- Remove the %YAML directive entirely if version declaration is not needed.
- Fix template placeholders so a literal version number is emitted.
- Catch SyntaxErrorException and surface the mark/line for the user to fix the directive.
Example fix
// before (input.yaml) %YAML 1. --- doc: true // after (input.yaml) %YAML 1.1 --- doc: true
Defensive patterns
Strategy: validation
Validate before calling
// C#
var m = System.Text.RegularExpressions.Regex.Match(yamlText ?? "", @"^%YAML\s+\d+\.\d+\s*$", System.Text.RegularExpressions.RegexOptions.Multiline);
if (yamlText != null && yamlText.Contains("%YAML") && !m.Success)
throw new FormatException("%YAML directive must be of the form '%YAML major.minor' (e.g. '%YAML 1.1')."); Try / catch
try { deserializer.Deserialize(reader, targetType); }
catch (SyntaxErrorException ex) { throw new YamlConfigException($"Incomplete %YAML version directive at line {ex.Start.Line}", ex); } Prevention
- Templates must substitute a literal version number, never placeholders.
- Validate directive lines with a regex before deserializing user-supplied YAML.
- Drop the %YAML directive if you don't need an explicit version.
When it happens
Trigger: Directives like '%YAML' alone, '%YAML .' or '%YAML 1.' (missing minor), or '%YAML x.y' where a non-digit appears where the version number must start.
Common situations: Truncated directive lines from failed edits; placeholders like '%YAML {version}' left by templates; files concatenated so the version digits ended up on the next line.
Related errors
- While parsing a tag directive, did not find expected '!'.
- While scanning a %YAML directive, find extremely long…
- Invalid version dependency format. Unable to decode
- Invalid version format. Unable to decode
- The anchor ' ' already exists
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/984dd8f32dc148e0.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Scanner.cs:2293
while (analyzer.IsDigit())
{
// Check if the number is too long.
if (++length > MaxVersionNumberLength)
{
throw new SyntaxErrorException(start, mark, "While scanning a %YAML directive, find extremely long version number.");
}
value = value*10 + analyzer.AsDigit();
Skip();
}
// Check if the number was present.
if (length == 0)
{
throw new SyntaxErrorException(start, mark, "While scanning a %YAML directive, did not find expected version number.");
}
return value;
}
/// <summary>
/// Check if a simple key may start at the current position and add it if
/// needed.
/// </summary>
private void SaveSimpleKey()
{
// A simple key is required at the current position if the scanner is in
// the block context and the current column coincides with the indentation
// level.
bool isRequired = (flowLevel == 0 && indent == mark.Column);
View on GitHub (pinned to 96fad776d2)