# Plot & StreamPlot eat my Messages

I have a complicated function for StreamPlot to call that includes some error checking and the use of Message. Somehow the messages are not displayed when the function is called from StreamPlot. Here's a toy example:

Define the function & message:

f[x_] := Module[{},
If[x > 1, Print["print: ", x]; Message[f::msg, x]];
x];

f::msg = "1 is greater than 1";


Test it by itself:

f[1.2]
(* print: 1.2 *)
(* f::msg f:1.2 is greater than 1 *)
(* 1.2 *)


Works as expected, but put it in a StreamPlot and only the Printed messages are shown:

StreamPlot[{f[x], y}, {x, 0, 1.2}, {y, 0, 1}]
(* txt: 1.22403 *)
(* txt: 1.22403 *)
(* ... *)


How can I get those Messages to show?

Update:

Plot eats Messages too.

• Oddly, it does not eat one of the messages here. – Michael E2 Mar 27 '17 at 19:09

You need to reset $Messages. f[x_] := Module[{}, If[x > 1, Print["print: ", x]; Block[{$Messages = Streams["stdout"]},
If[! ListQ@$MessageList,$MessageList = {}];
Message[f::msg, x]]];
x];


$MessageList should be a list, which if is not when f is called. Just what to do about it, whether to Block it too or reset it globally as above, I am not completely sure. It worked both ways with the following plot: Plot[f[x], {x, 0, 1.01}]  • Thanks! Seems like I will need to replace a lot of calls to Message with something like this. Could this be wrapped into a plug-and-play function with identical syntax to Message? Also, would you consider this a bug to report to WRI? – Chris K Mar 27 '17 at 20:16 • In response to my first question in the previous comment, seems so. Will add as a separate answer later tonight. – Chris K Mar 27 '17 at 21:53 Here's my attempt to wrap up @MichaelE2's trick into a plug-and-play replacement for Message: Msg[msgs__] := Block[{$Messages = Streams["stdout"]},
If[!ListQ@$MessageList,$MessageList = {}];
Message[msgs];
];
SetAttributes[Msg, HoldAll];


This seems to work except it usually overrules General::stop in Plot and StreamPlot`, which I can live with.