MCPcopy Create free account
hub / github.com/ChromeDevTools/devtools-frontend / buildErrorMessageForNinja

Function buildErrorMessageForNinja

scripts/devtools_build.mjs:215–259  ·  view source on GitHub ↗

* Constructs a human readable error message for the given build `error`. * * @param error the `Error` from the failed `autoninja` invocation. * @param outDir the absolute path to the `target` out directory. * @param target the target relative to `//out`. * @returns the human readable error mess

(error, outDir, target)

Source from the content-addressed store, hash-verified

213 * @returns the human readable error message.
214 */
215function buildErrorMessageForNinja(error, outDir, target) {
216 const { message, stderr, stdout } = error;
217 if (stderr) {
218 // Anything that went to stderr has precedence.
219 return `Failed to build \`${target}' in \`${outDir}'
220${stdout}
221${stderr}
222`;
223 }
224 if (stdout) {
225 // Check for `tsc` or `esbuild` errors in the stdout.
226 const tscErrors = [
227 ...stdout.matchAll(/^[^\s].*\(\d+,\d+\): error TS\d+:\s+.*$/gm),
228 ].map(([tscError]) => tscError);
229 if (!tscErrors.length) {
230 // We didn't find any `tsc` errors, but maybe there are `esbuild` errors.
231 // Transform these into the `tsc` format (with a made up error code), so
232 // we can report all TypeScript errors consistently in `tsc` format (which
233 // is well-known and understood by tools).
234 const esbuildErrors = stdout.matchAll(
235 /^✘ \[ERROR\] ([^\n]+)\n\n\s+\.\.\/\.\.\/(.+):(\d+):(\d+):/gm,
236 );
237 for (const [, message, filename, line, column] of esbuildErrors) {
238 tscErrors.push(
239 `${filename}(${line},${column}): error TS0000: ${message}`,
240 );
241 }
242 }
243 if (tscErrors.length) {
244 return `TypeScript compilation failed for \`${target}'
245
246${tscErrors.join('\n')}
247`;
248 }
249
250 // At the very least we strip `ninja: Something, something` lines from the
251 // standard output, since that's not particularly helpful.
252 const output = stdout.replaceAll(/^ninja: [^\n]+\n+/gm, '').trim();
253 return `Failed to build \`${target}' in \`${outDir}'
254
255${output}
256`;
257 }
258 return `Failed to build \`${target}' in \`${outDir}' (${message})`;
259}
260
261/** @enum {string} */
262export const BuildStep = {

Callers 1

constructorMethod · 0.85

Calls 5

trimMethod · 0.80
mapMethod · 0.45
pushMethod · 0.45
joinMethod · 0.45
replaceAllMethod · 0.45

Tested by

no test coverage detected