To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is
ClearAll[getFrontEndErrors];
SetAttributes[getFrontEndErrors, HoldAll];HoldAllComplete];
getFrontEndErrors[gexpr_]
getFrontEndErrors[expr_] :=
Module[Block[{nb, pinks},
UsingFrontEnd@Internal`WithLocalSettings[UsingFrontEnd[
nb = CreateDocument[gexprCreateDocument[ExpressionCell[expr, Visible -> False"Output"],
Visible -> False, NotebookFileName -> "FEMessages"];
SelectionMove[nb, All, Cell],Cell];
MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]],pinks = MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]];
NotebookClose[nb]
]];
pinks
];
which only returns the FE errors. (Edit: I removed the use of Internal`WithLocalSettings
as it has limitations that are counterproductive here.) Note, this creates and destroys a notebook. But, if you are posting the info to an existing notebook, you can bypass those steps and just call
MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]
which returns an empty list if there are no errors present. (You may have to preced the above code with UsingFrontEnd
.)