{"record":{"id":"ac68c0161c1678bb","repo":"withastro/astro","slug":"first-argument-must-be-a-string","errorCode":null,"errorMessage":"First argument must be a string","messagePattern":"First argument must be a string","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/integrations/markdoc/src/html/css/parse-inline-styles.ts","lineNumber":55,"sourceCode":"const NEWLINE = '\\n';\nconst FORWARD_SLASH = '/';\nconst ASTERISK = '*';\nconst EMPTY_STRING = '';\n\n// types\nconst TYPE_COMMENT = 'comment';\nconst TYPE_DECLARATION = 'declaration';\n\n/**\n * @param {String} style\n * @param {Object} [options]\n * @return {Object[]}\n * @throws {TypeError}\n * @throws {Error}\n */\nexport function parseInlineStyles(style, options) {\n\tif (typeof style !== 'string') {\n\t\tthrow new TypeError('First argument must be a string');\n\t}\n\n\tif (!style) return [];\n\n\toptions = options || {};\n\n\t/**\n\t * Positional.\n\t */\n\tlet lineno = 1;\n\tlet column = 1;\n\n\t/**\n\t * Update lineno and column based on `str`.\n\t *\n\t * @param {String} str\n\t */\n\tfunction updatePosition(str) {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/integrations/markdoc/src/html/css/parse-inline-styles.ts#L37-L73","documentation":"`parseInlineStyles` is a small hand-written CSS inline-style parser. Its contract requires the first argument be a string; any other type (number, undefined, null, object) throws `TypeError('First argument must be a string')`. An empty string short-circuits to `[]`.","triggerScenarios":"Calling `parseInlineStyles(value)` where `value` is `undefined`, `null`, a number, an object, or any non-string. Common when reading an attribute that may be absent (`element.attributes.style` returning undefined) and passing it through without coercion.","commonSituations":"Markdoc/MDX node whose `style` attribute is optional and not always present. Passing a parsed AST node instead of its string value. Defensive code path that forgets a null check.","solutions":["Guard the call: `if (typeof style === 'string') parseInlineStyles(style)`.","Coerce with a default: `parseInlineStyles(style ?? '')` (empty string returns `[]`).","Fix the upstream caller to only pass strings."],"exampleFix":"// before\nparseInlineStyles(node.attributes.style)\n\n// after\nparseInlineStyles(typeof node.attributes.style === 'string' ? node.attributes.style : '')","handlingStrategy":"type-guard","validationCode":"function safeParseInlineStyles(style: unknown) {\n  return typeof style === 'string' ? parseInlineStyles(style) : [];\n}","typeGuard":"function isStyleString(v: unknown): v is string {\n  return typeof v === 'string';\n}","tryCatchPattern":null,"preventionTips":["Always type the input as `string` in your wrapper.","Coerce optional attributes with `?? ''` before passing.","Unit-test the parser with undefined/null inputs."],"tags":["css","parsing","type-error","markdoc"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}