{"record":{"id":"0c0eb4039561acf8","repo":"saadeghi/daisyui","slug":"stderr","errorCode":null,"errorMessage":"${stderr}","messagePattern":"\\$\\{stderr\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/daisyui/functions/testUtils.js","lineNumber":26,"sourceCode":"  return {\n    make: async () => {\n      const dir = await mkdtemp(join(tmpdir(), prefix))\n      dirs.push(dir)\n      return dir\n    },\n    cleanup: async () => {\n      await Promise.all(dirs.map((dir) => rm(dir, { recursive: true, force: true })))\n      dirs = []\n    },\n  }\n}\n\nexport const runInCwd = async (cwd, code) => {\n  const proc = Bun.spawn([\"bun\", \"--eval\", code], { cwd, stderr: \"pipe\" })\n  const [exitCode, stderr] = await Promise.all([proc.exited, new Response(proc.stderr).text()])\n\n  if (exitCode !== 0) {\n    throw new Error(stderr)\n  }\n}\n","sourceCodeStart":8,"sourceCodeEnd":29,"githubUrl":"https://github.com/saadeghi/daisyui/blob/42b09e637e09467aa54a813a5aea53c1179aec75/packages/daisyui/functions/testUtils.js#L8-L29","documentation":"runInCwd spawns `bun --eval <code>` in the given cwd and re-throws the child's stderr verbatim when the subprocess exits non-zero. It is a daisyUI test helper used to assert runtime behaviour of generated plugin code in an isolated working directory. The thrown message is the child process's own diagnostic, not a fixed string.","triggerScenarios":"Calling runInCwd(cwd, code) where the eval'd code throws at runtime, has a syntax error, references an import that does not resolve in cwd, or where `bun` is not on PATH so the spawn fails.","commonSituations":"Test eval code that imports a module missing from the temp cwd; a relative import path that is wrong once Bun runs from cwd instead of the test file's directory; Bun version mismatch producing a different runtime error.","solutions":["Read the thrown stderr verbatim - it is the actual failing line/stack from the child.","Reproduce by hand: run `bun --eval \"<code>\"` from the same cwd the test used.","Fix the eval code or ensure the cwd has the modules/paths it imports.","If the spawn itself failed, confirm `bun` is on PATH in the test environment."],"exampleFix":"// before: eval code imports a path that only resolves from the test file dir\nawait runInCwd(tmpDir, `import x from \"./helper.js\"`)\n// after: use an absolute path or copy the helper into tmpDir first\nawait runInCwd(tmpDir, `import x from \"${JSON.stringify(helperAbsPath)}\"`)","handlingStrategy":"try-catch","validationCode":"// Validate the eval code parses before spawning a child.\nimport { parse } from \"node:path\"\nasync function safeRunInCwd(cwd, code) {\n  // Cheap parse check so a SyntaxError surfaces here, not as opaque stderr.\n  new Bun.Transpiler({}).transform(code) // throws on syntax error\n  return runInCwd(cwd, code)\n}","typeGuard":"// Confirm cwd is an existing directory before running.\nimport { stat } from \"node:fs/promises\"\nconst isDir = async (p) => { try { return (await stat(p)).isDirectory() } catch { return false } }","tryCatchPattern":"try {\n  await runInCwd(tmpDir, code)\n} catch (error) {\n  // error.message is the child's stderr; assert on it for negative tests.\n  if (!/expected pattern/.test(error.message)) throw error\n}","preventionTips":["Test the eval snippet with `bun --eval` in the same cwd before wiring it into a test.","Keep eval code free of relative imports; use absolute paths or copy deps into the temp cwd.","Treat the thrown message as the child stack - log it verbatim on failure."],"tags":["testing","bun","subprocess","eval"],"backgroundTag":null,"analyzedSha":"42b09e637e09467aa54a813a5aea53c1179aec75","analyzedAt":"2026-08-13T04:10:09.555Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}