{"record":{"id":"02fb34f411cbc6be","repo":"typst/typst","slug":"tag-must-be-one-to-four-characters-in-length","errorCode":null,"errorMessage":"tag must be one to four characters in length","messagePattern":"tag must be one to four characters in length","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/typst-library/src/text/font/tag.rs","lineNumber":99,"sourceCode":"// Tags must: https://learn.microsoft.com/en-us/typography/opentype/spec/otff#data-types\n// - be one to four bytes in length\n// - be representable as printable ASCII (0x20..=0x7E)\n// - contain at least one character that isn't padding (0x20, space)\n// - padding may only appear at the end of a tag\ncast! {\n    Tag,\n    v: Str => {\n        if let Some(cluster) = v.graphemes(true).find(|v| {\n            !v.as_bytes().iter().all(|v| (0x20..=0x7E).contains(v))\n        }) {\n            bail!(\n                \"tag may contain only printable ASCII characters\";\n                hint: \"found invalid cluster `{}`\", cluster.repr();\n            )\n        }\n\n        if !(1..=4).contains(&v.len()) {\n            bail!(\n                \"tag must be one to four characters in length\";\n                hint: \"found {} characters\", v.len();\n            );\n        }\n\n        let mut within_padding = false;\n        for (i, &v) in v.as_bytes().iter().enumerate() {\n            if (within_padding && v != b' ') || (i == 0 && v == b' ') {\n                bail!(\"spaces may only appear as padding following a tag\")\n            }\n            within_padding |= b' ' == v;\n        }\n\n        Self::from_bytes_lossy(v.as_bytes())\n    }\n}\n\nimpl From<Tag> for ttf_parser::Tag {","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/typst/typst/blob/35417aa769ab9d699a60384f91082b09bc6ba421/crates/typst-library/src/text/font/tag.rs#L81-L117","documentation":"Raised while casting a string to an OpenType Tag: OpenType tags are fixed at one to four bytes, but the string had zero or more than four characters.","triggerScenarios":"Thrown at crates/typst-library/src/text/font/tag.rs:99 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Shorten the tag to at most four characters, e.g. `\"kern\"`"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"35417aa769ab9d699a60384f91082b09bc6ba421","analyzedAt":"2026-08-17T21:03:48.984Z","contentChangedAt":"2026-08-17T21:03:48.984Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}