How to find a specific error message?
Here's a tiny utility function you might use if you're trying to look for a message that contains a known string:
searchMessages[str_String, opts___] :=
Sort[Select[Flatten[Map[ToExpression[#, InputForm, Defer] :>
Evaluate[ToExpression[#]] &,
StringCases[FindList[FileNameJoin[{$InstallationDirectory, "SystemFiles",
"Kernel", "TextResources", "English",
"Messages.m"}], str, opts,
IgnoreCase -> True],
RegularExpression["([\\w$]|`)+::(\\w)+"]], {2}]],
With[{s = Last[#]},
StringQ[s] && ! StringFreeQ[s, str, IgnoreCase -> True]] &]]
For example,
searchMessages["determinant"]
{TransferFunctionModel::method :>
"Value of option Method -> `1` is not Automatic, \"DeterminantExpansion\",
\"ResolventIdentities\", \"Inverse\", or Generic."}
The function tries to search for apropos messages within the Messages.m
file within the system files. It won't always find an appropriate message, since there are messages like General::offline
that aren't within Messages.m
(though grep
tells me that that particular message is in $InstallationDirectory <> "SystemFiles/Autoload/PacletManager/Kernel/Services.m"
, so you know what to modify). Still, it's a start...
We can scan the messages that have been loaded into the current session like this:
messages[pattern_, context_:"*"] :=
Cases[
Quiet[ToExpression[#, InputForm, Messages]& /@ Names[context~~"*"], General::readp]
, (_[n_] :> m_String) /; !StringFreeQ[m, pattern, IgnoreCase -> True] :> HoldForm@n :> m
, {2}
]
messages["arguments", "System`"]
(*
{General::bldim:>The arguments `1` and `2` in `3` do not have compatible dimensions.}
*)
messages["longer"]
(*
{General::partd:>Part specification `1` is longer than depth of object.,
Part::partd:>Part specification `1` is longer than depth of object.}
*)
The emphasis here is on loaded messages. This method will not find any messages in packages that have not yet been loaded. Also beware that some packages load symbols (and their messages) lazily, on demand.