{"record":{"id":"6f9bac95ab0cc187","repo":"saadeghi/daisyui","slug":"stdin-must-be-json-with-html-and-css-strings-er","errorCode":null,"errorMessage":"stdin must be JSON with html and css strings: ${error.message}","messagePattern":"stdin must be JSON with html and css strings: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/tailwind-play-share/index.mjs","lineNumber":156,"sourceCode":"async function resolveInput(options) {\n  let html = options.html\n  let css = options.css\n\n  if (options.htmlFile !== undefined) {\n    html = await readFile(resolve(options.htmlFile), \"utf8\")\n  }\n  if (options.cssFile !== undefined) {\n    css = await readFile(resolve(options.cssFile), \"utf8\")\n  }\n\n  if (html === undefined && css === undefined && !process.stdin.isTTY) {\n    const stdin = (await readStdin()).trim()\n    if (stdin) {\n      let parsed\n      try {\n        parsed = JSON.parse(stdin)\n      } catch (error) {\n        throw new Error(`stdin must be JSON with html and css strings: ${error.message}`)\n      }\n      html = parsed.html\n      css = parsed.css\n    }\n  }\n\n  if (html === undefined && css === undefined) {\n    throw new Error(\"Provide HTML/CSS using arguments, files, or JSON on stdin\")\n  }\n  if (html !== undefined && typeof html !== \"string\") {\n    throw new Error(\"html must be a string\")\n  }\n  if (css !== undefined && typeof css !== \"string\") {\n    throw new Error(\"css must be a string\")\n  }\n\n  return { html: html ?? \"\", css: css ?? \"\" }\n}","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/saadeghi/daisyui/blob/42b09e637e09467aa54a813a5aea53c1179aec75/packages/tailwind-play-share/index.mjs#L138-L174","documentation":"When stdin is not a TTY and html/css are still undefined, the script reads stdin, trims it, and tries JSON.parse. If parse throws, it re-throws with the parser's error message attached. The expected shape is an object with html and css string fields.","triggerScenarios":"Piping non-JSON text (raw HTML, CSS, or prose); malformed JSON (trailing comma, single quotes, unquoted keys); a leading BOM or log prefix before the JSON.","commonSituations":"echo'ing HTML directly into the pipe without wrapping in JSON; a CI step that prepends a timestamp line; JSON produced by a tool that emits comments.","solutions":["Pipe a valid JSON object: `{\"html\":\"...\",\"css\":\"...\"}`.","Strip any prefix/suffix lines around the JSON before piping.","If you only have raw text, use --html/--css or --html-file/--css-file instead of stdin."],"exampleFix":"# before\necho '<div>hi</div>' | bun .../index.mjs\n# after\necho '{\"html\":\"<div>hi</div>\",\"css\":\"\"}' | bun .../index.mjs","handlingStrategy":"try-catch","validationCode":"function tryParseJson(stdin) {\n  try { return JSON.parse(stdin) } catch { return undefined }\n}","typeGuard":"const looksLikeJson = (s) => { const t = s.trim(); return t.startsWith('{') && t.endsWith('}') }","tryCatchPattern":"try {\n  parsed = JSON.parse(stdin)\n} catch (error) {\n  throw new Error(`stdin must be JSON with html and css strings: ${error.message}`)\n}","preventionTips":["Always wrap stdin payloads as {\"html\":\"...\",\"css\":\"...\"}.","Strip log/timestamp lines before the JSON when piping from CI.","Prefer --html/--css for raw text to avoid JSON escaping pitfalls."],"tags":["cli","stdin","json","parsing"],"backgroundTag":null,"analyzedSha":"42b09e637e09467aa54a813a5aea53c1179aec75","analyzedAt":"2026-08-13T04:10:09.555Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}