@@ -3,7 +3,7 @@ module mcl.commands.ci_matrix;
33import std.stdio : writeln, stderr, stdout;
44import std.traits : EnumMembers;
55import std.string : indexOf, splitLines;
6- import std.algorithm : map, filter, reduce, chunkBy, find, any, sort, startsWith, each, canFind;
6+ import std.algorithm : map, filter, reduce, chunkBy, find, any, sort, startsWith, each, canFind, fold ;
77import std.file : write, readText;
88import std.range : array, front, join, split;
99import std.conv : to;
@@ -324,30 +324,23 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
324324
325325 auto pipes = pipeProcess(args, Redirect.stdout | Redirect.stderr);
326326
327- void logWarning (string errorMsg )
327+ void logWarning (const char [] msg )
328328 {
329- warningf(" Command `%s` stderr:\n ---\n %s\n ---" , commandString, errorMsg );
329+ warningf(" Command `%s` stderr:\n ---\n %s\n ---" , commandString, msg );
330330 }
331331
332- void logError (string errorMsg )
332+ void logError (const char [] msg )
333333 {
334- errorf(" Command `%s` failed with error:\n ---\n %s\n ---" , commandString, errorMsg );
334+ errorf(" Command `%s` failed with error:\n ---\n %s\n ---" , commandString, msg );
335335 }
336336
337- foreach (line; pipes.stdout.byLine)
338- {
339- if (line.indexOf(" {" ) == - 1 )
340- {
341- errorf(" Expected JSON object on stdout from nix-eval-jobs, got: `%s`" , line);
342- continue ;
343- }
344-
337+ const errorsReported = pipes.stdout.byLine.fold! ((errorsReported, line) {
345338 auto json = parseJSON(line);
346339
347340 if (auto err = " error" in json)
348341 {
349342 logError((* err).str);
350- continue ; // drain the output
343+ return true ;
351344 }
352345
353346 Package pkg = json.packageFromNixEvalJobsJson(
@@ -370,17 +363,19 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
370363 attr: pkg.attrPath,
371364 output: pkg.output
372365 ).writeRecordAsTable(stderr.lockingTextWriter);
373- }
366+
367+ return errorsReported;
368+ })(false );
374369
375370 const stderrLogs = pipes.stderr.byLine
376371 .filter! (line => ! uselessWarnings.canFind(line))
377- .join(" \n " )
378- .idup;
372+ .join(" \n " );
379373
380374 logWarning(stderrLogs);
381375
382376 int status = wait(pipes.pid);
383- enforce(status == 0 , " Command `%s` failed with status %s" .fmt(args, status));
377+
378+ enforce(status == 0 && ! errorsReported, " Command `%s` failed with status %s" .fmt(commandString, status));
384379
385380 return result;
386381}
0 commit comments