stride3d/stride · error · SyntaxErrorException

While scanning a tag, did not find expected whitespace or…

Error message

While scanning a tag, did not find expected whitespace or line break.

What it means

After scanning a tag token (plain '!handle!suffix' or verbatim '!<...>'), ScanTag requires the next character to be a blank, line break, or end of input — a tag must be followed by whitespace. If a non-space character (e.g. a comma, letter, or quote) immediately follows the tag, this SyntaxErrorException is thrown.

Solutions

  1. Insert a space after the tag: change 'key:!foo value' to 'key: !foo value'.
  2. Ensure a tag appears only in tag positions — before a scalar, mapping, or sequence — never mid-token.
  3. Check the reported column: the character right after the tag must be whitespace, newline, or EOF.
  4. If the tag was intended as plain content, escape or quote it (e.g. "'!foo,value'") so the scanner treats it as a string.
  5. Run a YAML linter over the document to catch missing whitespace around tags.

Example fix

// before (no space after tag)
key:!custom value

// after
key: !custom value
Defensive patterns

Strategy: validation

Validate before calling

static bool TagsAreWhitespaceDelimited(string yaml)
{
    // a tag char sequence like !foo must be followed by space, newline, or EOF
    return !System.Text.RegularExpressions.Regex.IsMatch(yaml, "![A-Za-z0-9][^ \\t\\n\\r,\\[{]");
}

Try / catch

try
{
    var obj = deserializer.Deserialize<T>(input);
}
catch (YamlException ex)
{
    throw new FormatException($"Tag not followed by whitespace near {ex.Start.Line}:{ex.Start.Column}", ex);
}

Prevention

When it happens

Trigger: Writing a tag glued to surrounding content without a space, e.g. 'key:!foo' or '!tag,value', or two tags in a row '!a!!b'. Any parse of such input via Deserializer/YamlStream reaches the check after tag URI scanning and throws.

Common situations: Concatenated YAML where a tag was appended directly to a key or value without a separating space, macro/template expansion producing '!foo,value', and hand-edited manifests where a space was accidentally deleted after a custom tag.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/2f40571b7a1b62a1. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Scanner.cs:1278


                    // A special case: the '!' tag.  Set the handle to '' and the
                    // suffix to '!'.


                    if (suffix.Length == 0)
                    {
                        suffix = handle;
                        handle = string.Empty;
                    }
                }
            }

            // Check the character which ends the tag.

            if (!analyzer.IsBlankOrBreakOrZero())
            {
                throw new SyntaxErrorException(start, mark, "While scanning a tag, did not find expected whitespace or line break.");
            }

            // Create a token.

            return new Tag(handle, suffix, start, mark);
        }

        /// <summary>
        /// Produce the SCALAR(...,literal) or SCALAR(...,folded) tokens.
        /// </summary>
        private void FetchBlockScalar(bool isLiteral)
        {
            // Remove any potential simple keys.

            RemoveSimpleKey();

            // A simple key may follow a block scalar.

View on GitHub (pinned to 96fad776d2)