The behaviour we see is due to the default FailureAction associated with dataset queries. The default action is to abort the entire computation if any message is issued:
data[All, If[#A == 1, #, Message[f::test]] &]
(* Failure[...] *)
Fortunately, we can override this behaviour. For example, we can instruct the query to take no special action in the face of messages:
data[All, If[#A == 1, #, f[#]] &, FailureAction -> None]
(*
f: -- Message text not found --
{ <| "A" -> 1|>, <| "B" -> 1 |> }
*)
Messages are issued as normal and the final dataset is produced. Incidentally, this option is incredibly useful when debugging complex dataset queries.
We can also drop each individual result if its computation issues a message:
data[All, If[#A == 1, #, f[#]] &, FailureAction -> "Drop"]
(* { <| "A" -> 1 |> } *)
... or encapsulate individual failed results within Failure
objects:
data[All, If[#A == 1, #, f[#]] &, FailureAction -> "Encapsulate"]
(* <| "A" -> 1 |>, Failure[...] } *)
... or replace failed results with a Missing
expression:
data[All, If[#A == 1, #, f[#]] &, FailureAction -> "Replace"]
(* {<|"A" -> 1|>, Missing["Failed"]} *)
We can enhance most of the action types with a user function which is applied to Failure
objects (the function g
in this example):
data[All, If[#A == 1, #, f[#]] &, FailureAction -> {"Replace", g}]
(* { <| "A" -> 1 |>, g[Failure[...]] } *)
Finally, we can explicitly specify the "Abort" action which is the default:
data[All, If[#A == 1, #, f[#]] &, FailureAction -> "Abort"]
(* Failure[...] *)
Quiet
? $\endgroup$ – Edmund Sep 23 '16 at 1:06