{"record":{"id":"42092f2b8f200780","repo":"mjmlio/mjml","slug":"e-formattedmessage-compiled-mjml-errors-printed-v","errorCode":null,"errorMessage":"e.formattedMessage (compiled MJML errors printed via console.warn)","messagePattern":"e\\.formattedMessage \\(compiled MJML errors printed via console\\.warn\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/mjml-cli/src/commands/watchFiles.js","lineNumber":62,"sourceCode":"\n    watcher.add(difference(files.toWatch, files.watched))\n    watcher.unwatch(difference(files.watched, files.toWatch))\n    /* eslint-enable no-use-before-define */\n  }\n  const readAndCompile = async (file) => {\n    const { config } = options\n    const beautify = config.beautify && config.beautify !== 'false'\n    const minify = config.minify && config.minify !== 'false'\n    const content = readFile(file).mjml\n    const compiled = await mjml2html(content, {\n      ...config,\n      beautify,\n      minify,\n      filePath: file,\n      actualPath: file,\n    })\n\n    compiled.errors.forEach((e) => console.warn(e.formattedMessage))\n\n    try {\n      await outputToFile({ file, compiled })\n      console.log(`${file} - Successfully compiled`)\n    } catch (e) {\n      console.log(`${file} - Error while compiling file`)\n    }\n  }\n\n  const watcher = chokidar\n    .watch(input.map((i) => i.replace(/\\\\/g, '/')))\n    .on('change', (file) => synchronyzeWatcher(path.resolve(file)))\n    .on('add', (file) => {\n      const filePath = path.resolve(file)\n      console.log(`Now watching file: ${filePath}`)\n\n      const matchInputOption = input.reduce(\n        (found, file) =>","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/mjmlio/mjml/blob/6c01d35af5da14108b86bbf052232e99de7ca755/packages/mjml-cli/src/commands/watchFiles.js#L44-L80","documentation":"Not a thrown error but a diagnostic output path: in watchFiles' readAndCompile, when mjml2html returns compiled.errors, each error's formattedMessage is printed via console.warn so watch-mode users see validation/parse warnings with file/line context while compilation continues. The file is still written if outputToFile succeeds; warnings indicate issues without aborting the watch loop.","triggerScenarios":"Running `mjml --watch` on a directory while a watched file contains validation errors (unknown components, bad attributes) or recoverable parse issues — mjml2html returns an errors array which readAndCompile prints line by line.","commonSituations":"Live-editing templates in an editor and saving intermediate broken states; auto-formatters introducing invalid attributes; partial files being written while the watcher compiles them mid-save.","solutions":["Read each printed formattedMessage; fix the reported file/line so warnings disappear on the next save.","Ignore transient warnings during rapid successive saves; re-save once editing is complete.","Harden the watch pipeline by validating files (mjml --validate or validationLevel checks) before output.","If warnings should block output, wrap compilation and check compiled.errors before calling outputToFile."],"exampleFix":"// before: compile and always output\ncompiled.errors.forEach((e) => console.warn(e.formattedMessage))\nawait outputToFile({ file, compiled })\n// after: optionally skip output on errors\nif (compiled.errors.length) {\n  compiled.errors.forEach((e) => console.warn(e.formattedMessage))\n  return // skip writing broken output\n}\nawait outputToFile({ file, compiled })","handlingStrategy":"try-catch","validationCode":"const fs = require('fs');\nif (!fs.existsSync(file)) { console.error(`Watched file vanished: ${file}`); return; }\nif (!fs.readFileSync(file, 'utf8').trim()) { console.warn(`Skipped empty file: ${file}`); return; }","typeGuard":null,"tryCatchPattern":"const compiled = mjml2html(source, { beautify, minify, filePath: file })\nif (compiled.errors.length) {\n  compiled.errors.forEach((e) => console.warn(e.formattedMessage))\n  // decide: continue writing (warn-only) or return to block output\n}\ntry {\n  await outputToFile({ file, compiled })\n} catch (e) {\n  console.error(`${file} - output failed:`, e.message)\n}","preventionTips":["Treat formattedMessage output as a signal to fix templates, not noise.","Add editor linting for MJML so errors are caught before saving.","Consider gating watch output on compiled.errors.length in strict pipelines."],"tags":["cli","watch","validation","diagnostics"],"backgroundTag":"mjml-validation-warnings","analyzedSha":"6c01d35af5da14108b86bbf052232e99de7ca755","analyzedAt":"2026-09-02T21:31:03.649Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}