@@ -151,50 +151,97 @@ let fire_notification
151151 send_request connection name ~f: (fun client -> notify_exn client notification arg)
152152;;
153153
154+ let print_err_warn_alert =
155+ let plural x = if x = 1 then " " else " s" in
156+ function
157+ | 0 , 0 , 0 ->
158+ Code_error. raise
159+ " Build via RPC failed, but the RPC server did not send an error message."
160+ []
161+ | 0 , 0 , a ->
162+ User_warning. emit
163+ [ Pp. paragraphf " Build completed with %d alert%s." a (plural a)
164+ |> Pp. tag User_message.Style. Warning
165+ ]
166+ | 0 , w , 0 ->
167+ User_warning. emit
168+ [ Pp. paragraphf " Build completed with %d warning%s." w (plural w)
169+ |> Pp. tag User_message.Style. Warning
170+ ]
171+ | 0 , w , a ->
172+ User_warning. emit
173+ [ Pp. paragraphf
174+ " Build completed with %d warning%s and %d alert%s."
175+ w
176+ (plural w)
177+ a
178+ (plural a)
179+ |> Pp. tag User_message.Style. Warning
180+ ]
181+ | e , 0 , 0 ->
182+ User_error. raise
183+ [ Pp. paragraphf " Build failed with %d error%s." e (plural e)
184+ |> Pp. tag User_message.Style. Error
185+ ]
186+ | e , 0 , a ->
187+ User_error. raise
188+ [ Pp. paragraphf
189+ " Build failed with %d error%s and %d alert%s."
190+ e
191+ (plural e)
192+ a
193+ (plural a)
194+ |> Pp. tag User_message.Style. Error
195+ ]
196+ | e , w , 0 ->
197+ User_error. raise
198+ [ Pp. paragraphf
199+ " Build failed with %d error%s and %d warning%s."
200+ e
201+ (plural e)
202+ w
203+ (plural w)
204+ |> Pp. tag User_message.Style. Error
205+ ]
206+ | e , w , a ->
207+ User_error. raise
208+ [ Pp. paragraphf
209+ " Build failed with %d error%s, %d warning%s, and %d alert%s."
210+ e
211+ (plural e)
212+ w
213+ (plural w)
214+ a
215+ (plural a)
216+ |> Pp. tag User_message.Style. Error
217+ ]
218+ ;;
219+
154220let wrap_build_outcome_exn ~print_on_success build_outcome =
155221 match build_outcome with
156222 | Dune_rpc.Build_outcome_with_diagnostics. Success ->
157223 if print_on_success
158224 then Console. print [ Pp. text " Success" |> Pp. tag User_message.Style. Success ]
159225 | Failure errors ->
160- let nb_errors, nb_warnings =
226+ let nb_errors, nb_warnings, nb_alerts =
161227 List. fold_left
162228 errors
163- ~init: (0 , 0 )
229+ ~init: (0 , 0 , 0 )
164230 ~f:
165231 (fun
166- (nb_errors , nb_warnings ) { Dune_rpc.Compound_user_error. main; severity; _ } ->
232+ (nb_errors , nb_warnings , nb_alerts )
233+ { Dune_rpc.Compound_user_error. main; severity; _ }
234+ ->
167235 match severity with
168236 | Error ->
169237 Console. print_user_message main;
170- nb_errors + 1 , nb_warnings
238+ nb_errors + 1 , nb_warnings, nb_alerts
171239 | Warning ->
172240 User_warning. emit_message main;
173- nb_errors, nb_warnings + 1 )
241+ nb_errors, nb_warnings + 1 , nb_alerts
242+ | Alert ->
243+ Console. print_user_message main;
244+ nb_errors, nb_warnings, nb_alerts + 1 )
174245 in
175- (match nb_errors, nb_warnings with
176- | 0 , 0 ->
177- Code_error. raise
178- " Build via RPC failed, but the RPC server did not send an error message."
179- []
180- | 0 , n ->
181- User_warning. emit
182- [ Pp. paragraphf
183- " Build completed with %d warning%s."
184- n
185- (if n = 1 then " " else " s" )
186- |> Pp. tag User_message.Style. Warning
187- ]
188- | n , m ->
189- User_error. raise
190- [ Pp. paragraphf
191- " Build failed with %d error%s%s."
192- n
193- (if n = 1 then " " else " s" )
194- (match m with
195- | 0 -> " "
196- | 1 -> " and 1 warning"
197- | m -> " and " ^ string_of_int m ^ " warnings" )
198- |> Pp. tag User_message.Style. Error
199- ])
246+ print_err_warn_alert (nb_errors, nb_warnings, nb_alerts)
200247;;
0 commit comments