{"record":{"id":"9e1afd8f53c68d9d","repo":"stride3d/stride","slug":"tag-handle-must-start-and-end-with-and-contain","errorCode":null,"errorMessage":"Tag handle must start and end with '!' and contain alphanumerical characters only.","messagePattern":"Tag handle must start and end with '!' and contain alphanumerical characters only\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Tokens/TagDirective.cs","lineNumber":101,"sourceCode":"\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"TagDirective\"/> class.\n        /// </summary>\n        /// <param name=\"handle\">The handle.</param>\n        /// <param name=\"prefix\">The prefix.</param>\n        /// <param name=\"start\">The start position of the token.</param>\n        /// <param name=\"end\">The end position of the token.</param>\n        public TagDirective(string handle, string prefix, Mark start, Mark end)\n            : base(start, end)\n        {\n            if (string.IsNullOrEmpty(handle))\n            {\n                throw new ArgumentNullException(\"handle\", \"Tag handle must not be empty.\");\n            }\n\n            if (!tagHandleValidator.IsMatch(handle))\n            {\n                throw new ArgumentException(\"Tag handle must start and end with '!' and contain alphanumerical characters only.\", \"handle\");\n            }\n\n            this.handle = handle;\n\n            if (string.IsNullOrEmpty(prefix))\n            {\n                throw new ArgumentNullException(\"prefix\", \"Tag prefix must not be empty.\");\n            }\n\n            this.prefix = prefix;\n        }\n\n        /// <summary>\n        /// Determines whether the specified System.Object is equal to the current System.Object.\n        /// </summary>\n        /// <param name=\"obj\">The System.Object to compare with the current System.Object.</param>\n        /// <returns>\n        /// true if the specified System.Object is equal to the current System.Object; otherwise, false.","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Tokens/TagDirective.cs#L83-L119","documentation":"TagDirective's constructor throws ArgumentException when the tag handle fails the tagHandleValidator regex: it must start and end with '!' and contain only alphanumerical characters between (e.g. '!e!'). This enforces the YAML tag-shorthand grammar before the token is accepted.","triggerScenarios":"Parsing a %TAG directive whose handle is malformed, e.g. `%TAG e! tag:...` (missing leading '!') or `%TAG !e tag:...` (missing trailing '!'), or constructing TagDirective directly with such a handle.","commonSituations":"Typo'd YAML tag directives in config files; YAML authored by hand or generated by tools that don't validate the tag-shorthand syntax.","solutions":["Rewrite the handle to match !name! (leading and trailing '!', alphanumeric middle), e.g. `!e!`.","Validate with the same regex before constructing/parsing: `^![0-9A-Za-z]*!$`.","Use the primary handle `!` alone if no named shorthand is required."],"exampleFix":"// before (YAML)\n%TAG e! tag:example.com,2000:\n// after (YAML)\n%TAG !e! tag:example.com,2000:","handlingStrategy":"validation","validationCode":"var tagHandleRegex = new System.Text.RegularExpressions.Regex(\"^![0-9A-Za-z]*!$\");\nif (string.IsNullOrEmpty(handle) || !tagHandleRegex.IsMatch(handle))\n    throw new ArgumentException($\"Invalid tag handle '{handle}': must be !name! with alphanumerics only.\");","typeGuard":"static bool IsValidTagHandle(string h) => h != null && System.Text.RegularExpressions.Regex.IsMatch(h, \"^![0-9A-Za-z]*!$\");","tryCatchPattern":"try { return new TagDirective(handle, prefix, start, end); }\ncatch (ArgumentException ex) { throw new YamlSyntaxException($\"Invalid tag shorthand in %TAG directive: {ex.Message}\", start); }","preventionTips":["Follow the YAML spec's ns-tag-char grammar when authoring handles.","Test YAML files containing %TAG directives in CI with a YAML linter.","When generating handles, always format as '!' + alphanumeric name + '!'."],"tags":["yaml","invalid-argument-format","directive"],"backgroundTag":"invalid-argument-format","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"}