stride3d/stride · error · ArgumentException

Tag value must not be empty.

Error message

Tag value must not be empty.

What it means

NodeEvent's constructor validates optional anchor and tag strings. A tag (the type identifier like !!str or !custom) may be null but must not be a zero-length string; an empty tag means the YAML producer emitted a malformed node property. The library throws ArgumentException to fail fast rather than propagate a corrupt event into the parser/emitter pipeline.

Solutions

  1. Check that the tag string is null or non-empty before constructing the NodeEvent
  2. If a node has no tag, pass null instead of the empty string
  3. Trim and validate the tag came from a complete tag property (e.g. '!!str' not a bare '!!')

Example fix

// before
var evt = new NodeEvent(anchor, tag: "", ...);
// after
var evt = new NodeEvent(anchor, tag: string.IsNullOrEmpty(rawTag) ? null : rawTag, ...);
Defensive patterns

Strategy: validation

Validate before calling

if (tag != null && tag.Length == 0) throw new ArgumentException("tag must be null or non-empty"); var evt = new NodeEvent(anchor, tag, ...);

Type guard

static bool IsValidTag(string tag) => tag == null || tag.Length > 0;

Try / catch

try { var evt = new NodeEvent(anchor, tag); } catch (ArgumentException ex) when (ex.ParamName == "tag") { /* fall back to null tag */ }

Prevention

When it happens

Trigger: Calling the NodeEvent constructor (directly or via an event emitter) with tag: "" — e.g. building YamlStream events programmatically or forwarding a tag parsed from a fragment that had '!!' or '!' with nothing after it.

Common situations: Programmatic YAML document construction, string-splitting a tag directive like '!!str' on '!!' and passing the empty remainder, templating engines that substitute an empty value for a tag placeholder.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Events/NodeEvent.cs:105

        protected NodeEvent(string anchor, string tag, Mark start, Mark end)
            : base(start, end)
        {
            if (anchor != null)
            {
                if (anchor.Length == 0)
                {
                    throw new ArgumentException("Anchor value must not be empty.", "anchor");
                }

                if (!anchorValidator.IsMatch(anchor))
                {
                    throw new ArgumentException("Anchor value must contain alphanumerical characters only.", "anchor");
                }
            }

            if (tag != null && tag.Length == 0)
            {
                throw new ArgumentException("Tag value must not be empty.", "tag");
            }

            this.anchor = anchor;
            this.tag = tag;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="NodeEvent"/> class.
        /// </summary>
        protected NodeEvent(string anchor, string tag)
            : this(anchor, tag, Mark.Empty, Mark.Empty)
        {
        }
    }
}

View on GitHub (pinned to 96fad776d2)