How to access Basic compiler error for programmatic usage

In the Basic IDE, if you have syntax errors and try to compile or run a macro, you’ll get an error message explaining the issue. Is it possible to get that error message by any other means?

The closest I have been able to come is to load a library and check whether a module is missing a function it should have, meaning that it didn’t compile. For example, if you LoadLibrary(libraryWithBadSyntaxModule) and try to run a function from the broken module, BrokenModule.someFn(), you’ll get an error Incorrect property value at the line where you tried to call that function. Ideally, you would get the the syntax error and the line number of it within its module instead.

I’ve been trying to find some api to manually compile() and get the error, but no luck. I see some relevant looking things under com.sun.star.script.XEngine, but it is deprecated and seems to be removed. I’d be fine with using executeDispatch to open the ide, load the module (or even paste it from a string), hit the compile button, and get the message that way, but I haven’t been able to get .uno:CompileBasic to cause anything to happen. If I could access the compile function and get this message from another language, or the terminal (i.e. bash), that would be fine, too. If the best that can be done is to invoke it from the source (c++?), I’d be interested in an approach like that if it is reasonably accessible.