{"record":{"id":"83814be16622b5d8","repo":"stride3d/stride","slug":"anchor-value-must-not-be-empty-nodeevent","errorCode":null,"errorMessage":"Anchor value must not be empty.","messagePattern":"Anchor value must not be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Events/NodeEvent.cs","lineNumber":94,"sourceCode":"        /// </summary>\n        /// <value></value>\n        public abstract bool IsCanonical { get; }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"NodeEvent\"/> class.\n        /// </summary>\n        /// <param name=\"anchor\">The anchor.</param>\n        /// <param name=\"tag\">The tag.</param>\n        /// <param name=\"start\">The start position of the event.</param>\n        /// <param name=\"end\">The end position of the event.</param>\n        protected NodeEvent(string anchor, string tag, Mark start, Mark end)\n            : base(start, end)\n        {\n            if (anchor != null)\n            {\n                if (anchor.Length == 0)\n                {\n                    throw new ArgumentException(\"Anchor value must not be empty.\", \"anchor\");\n                }\n\n                if (!anchorValidator.IsMatch(anchor))\n                {\n                    throw new ArgumentException(\"Anchor value must contain alphanumerical characters only.\", \"anchor\");\n                }\n            }\n\n            if (tag != null && tag.Length == 0)\n            {\n                throw new ArgumentException(\"Tag value must not be empty.\", \"tag\");\n            }\n\n            this.anchor = anchor;\n            this.tag = tag;\n        }\n\n        /// <summary>","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Events/NodeEvent.cs#L76-L112","documentation":"NodeEvent is the base class of scalar/sequence/mapping events; when an anchor is supplied it must be non-empty. Unlike the alias variant, this check throws System.ArgumentException (not YamlException) because it is a constructor argument validation on the event object itself.","triggerScenarios":"Passing anchor: \"\" (not null) to a ScalarEvent/SequenceStartEvent/MappingStartEvent constructor, e.g. new Scalar(\"\", tag, value, ...) — null means 'no anchor', empty string is invalid.","commonSituations":"Serialization code that defaults anchors with string.Empty instead of null; template interpolation producing \"\"; converters that emit an anchor attribute for every node even when empty.","solutions":["Pass null instead of \"\" when a node has no anchor","Coerce empty strings to null before constructing the event","Validate anchor names before building node events","Fix producers that initialize anchor fields to empty strings"],"exampleFix":"// before\nvar evt = new Scalar(anchor ?? \"\", tag, value, style, true, false, start, end);\n// after\nvar evt = new Scalar(string.IsNullOrEmpty(anchor) ? null : anchor, tag, value, style, true, false, start, end);","handlingStrategy":"validation","validationCode":"string safeAnchor = string.IsNullOrEmpty(anchor) ? null : anchor;\nif (safeAnchor != null && !safeAnchor.All(char.IsLetterOrDigit)) throw new ArgumentException(\"Invalid anchor\");","typeGuard":null,"tryCatchPattern":"try { var evt = new Scalar(anchor, tag, value, style, true, false, start, end); }\ncatch (ArgumentException ex) when (ex.ParamName == \"anchor\") { /* coerce to null and rebuild */ }","preventionTips":["Use null, not string.Empty, for 'no anchor'","Catch ArgumentException (not YamlException) around node event constructors","Normalize anchor fields at the source so they are either null or valid"],"tags":["yaml","anchor","argument-exception"],"backgroundTag":"empty-required-field","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}