Detect Stack Traces

Discussion in 'Plugin Development' started by Stigosaurus, Jul 9, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Stigosaurus

    Hello, I'm making a plugin that alerts developers (really just players with a permission) when a stack trace occurs in console. I'd like to be able to send live messages containing the exception (e.g. "NullPointerException"), the package, and the line number, so the instant a stack trace occurs it alerts staff. I know how to do the messaging and stuff, but how can I detect when an exception occurs? Any help is appreciated!
     
  2. Offline

    Wizehh

    Well, would these errors be coming your plugin? It'd be a bit more complicated if you want to detect errors from other plugins.
     
  3. Offline

    Stigosaurus

    Wizehh all errors from all plugins. You know, those ones that spam 20 lines in console.
     
  4. Offline

    teej107

    Code:java
    1. System.setOut();
    I don't know how well that would work though. Since it completely hijacks printing to the console.

    EDIT: This is for everything. Not just errors.
     
  5. This is pretty much impossible. You can't know when something threw an exception and then read it and get the things you want to know. If you were able to do so, that would be amazing. But you can't.
     
  6. Offline

    Stigosaurus

  7. Offline

    chasechocolate

    Interesting concept; I got a few potential ideas that I'll test tomorrow.
     
    Stigosaurus likes this.
  8. Offline

    chasechocolate

    Stigosaurus TheBigSuperCraft Wizehh teej107 <: it's very much possible. Here's just a proof of concept that it can be done.

    [mod edit: Removed third party build information]

    For those who want to know how it's done: Catching outgoing log messages ;)
     
    Stigosaurus likes this.
  9. Offline

    Cirno

    It's possible; a few ideas that come to mind:
    Hijack the SimpleCommandMap dispatch method and catching all errors there. (this will only work for command related errors)
    Hijack System.err with System.setErr (but I don't think Bukkit prints out the stacktrace with printStackTrace; I think it prints it out to it's own logger)
    You could possibly go bytecode level and basically rewrite plugins; but this will be very very tedious and probably not worth the effort.

    A very very stupid theory:
    Find a way to hack the Throwable class constructors. If you can screw with the constructors, you can pretty much manipulate errors to your will.
     
  10. Offline

    xTigerRebornx

    Cirno Could a console filter work?
    Filter the console's output, detect if it is a stacktrace (Patterns?), then grab information based on the stracktrace
     
  11. Offline

    unrealdesign

    That's exactly what chasechocolate did
     
  12. Offline

    chasechocolate

    Cirno xTigerRebornx yeah you're on the right track. Bukkit.getLogger().addHandler(...)
     
    Stigosaurus likes this.
Thread Status:
Not open for further replies.

Share This Page