enebo / Purugin

Ruby Minecraft Plugin support on top of bukkit
238 stars 32 forks source link

Execute system command causes Error #35

Closed NigelThorne closed 11 years ago

NigelThorne commented 12 years ago

With this plugin...

class TranslatePlugin
   include Purugin::Plugin
   description( 'Translate', 0.3 )

   def on_enable
     event(:async_player_chat) do |e|
      translate =   "rtranslate  \"#{e.message}\" -f en -t fr -k xxxxxxxxxxxx"
      translated = %x{translate}
       e.message = "#{e.message} :\n #{translated}"
     end
   end
 end

I get

23:13:34 [SEVERE] Could not pass event AsyncPlayerChatEvent to Translate v0.3
org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:459)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:829)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:806)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
    at net.minecraft.server.NetworkManager.i(NetworkManager.java:211)
    at net.minecraft.server.NetworkManager.c(NetworkManager.java:332)
    at net.minecraft.server.NetworkReaderThread.run(SourceFile:101)
Caused by: org.jruby.exceptions.RaiseException: (Errno::EBADF) Bad file descriptor
    at org.jruby.RubyIO.read(org/jruby/RubyIO.java:2904)
    at RUBY.`(file:/home/nigel/projects/4giggles/minecraftserver/plugins/purugin-0.1-bukkit-1.3.2-R2.0-SNAPSHOT.jar!/jruby/kernel/jruby/process_manager.rb:35)
    at RUBY.`(file:/home/nigel/projects/4giggles/minecraftserver/plugins/purugin-0.1-bukkit-1.3.2-R2.0-SNAPSHOT.jar!/jruby/kernel/jruby/process_manager.rb:49)
    at RUBY.on_enable(/home/nigel/projects/4giggles/minecraftserver/plugins/translateplugin.rb:31)
    at org.jruby.RubyProc.call(org/jruby/RubyProc.java:249)
    at RUBY.on_event(/home/nigel/projects/4giggles/minecraftserver/plugins/translateplugin.rb:14)
    ... 1 more

What's the correct way to trigger a system call and get the result back in JRuby in Purugin ?

Thanks Nigel

enebo commented 12 years ago

Sorry I was busy preparing for rubyconf. One thing I recommend is adding a begin/rescue in your event block. Unfortunately, error reporting is not as good as it could be:

     event(:async_player_chat) do |e|
      begin
        translate =   "rtranslate  \"#{e.message}\" -f en -t fr -k xxxxxxxxxxxx"
        translated = %x{translate}
        e.message = "#{e.message} :\n #{translated}"
      rescue
         puts "WTF: $!" 
      end
     end

I should try and not swallow these errors in event handling for the next release but hopefully this will uncover what is going on.

NigelThorne commented 12 years ago

I just get the same exception

org.jruby.exceptions.RaiseException: (Errno::EBADF) Bad file descriptor
    at org.jruby.RubyIO.read(org/jruby/RubyIO.java:2904)
    at RUBY.`(file:/home/nigel/projects/4giggles/minecraftserver/plugins/purugin-0.1-bukkit-1.3.2-R2.0-SNAPSHOT.jar!/jruby/kernel/jruby/process_manager.rb:35)
    at RUBY.`(file:/home/nigel/projects/4giggles/minecraftserver/plugins/purugin-0.1-bukkit-1.3.2-R2.0-SNAPSHOT.jar!/jruby/kernel/jruby/process_manager.rb:49)
    at RUBY.on_enable(/home/nigel/projects/4giggles/minecraftserver/plugins/translateplugin.rb:31)
    at org.jruby.RubyProc.call(org/jruby/RubyProc.java:249)
    at RUBY.on_event(/home/nigel/projects/4giggles/minecraftserver/plugins/translateplugin.rb:14)

looks like Ruby.` causes a problem.

I'll try calling Java directly making a Process object.

enebo commented 12 years ago

Interesting. This perhaps is an issue with 1.7.0. Can you also provide OS and JVM you are using? I would like to fix this for JRuby 1.7.1 if we can isolate it. Can you also remove this snippet out of Purugin and just try executing this directly as its own script?

enebo commented 11 years ago

Nigel, I am closing this out unless you have more info. There has been changes to Purugin, but I really think this may be an env issue of some kind. Re-open if you have more info.