mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
bubble up java stacktrace from wrapped exception
move exception builder in RubyUtil cosmetic cosmetic
This commit is contained in:
parent
1340f2eee0
commit
be20242d6f
4 changed files with 23 additions and 10 deletions
|
@ -1,6 +1,8 @@
|
||||||
package org.logstash;
|
package org.logstash;
|
||||||
|
|
||||||
|
import org.jruby.NativeException;
|
||||||
import org.jruby.Ruby;
|
import org.jruby.Ruby;
|
||||||
|
import org.jruby.exceptions.RaiseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities around interaction with the {@link Ruby} runtime.
|
* Utilities around interaction with the {@link Ruby} runtime.
|
||||||
|
@ -30,4 +32,16 @@ public final class RubyUtil {
|
||||||
ruby.getOrCreateModule(LS_MODULE_NAME);
|
ruby.getOrCreateModule(LS_MODULE_NAME);
|
||||||
return ruby;
|
return ruby;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a Java exception in a JRuby IOError NativeException.
|
||||||
|
* This preserves the Java stacktrace and bubble up as a Ruby IOError
|
||||||
|
* @param runtime the Ruby runtime context
|
||||||
|
* @param e the Java exception to wrap
|
||||||
|
* @return RaiseException the wrapped IOError
|
||||||
|
*/
|
||||||
|
public static RaiseException newRubyIOError(Ruby runtime, Throwable e) {
|
||||||
|
// will preserve Java stacktrace & bubble up as a Ruby IOError
|
||||||
|
return new RaiseException(e, new NativeException(runtime, runtime.getIOError(), e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.logstash.ackedqueue.Batch;
|
||||||
import org.logstash.Event;
|
import org.logstash.Event;
|
||||||
import org.logstash.ackedqueue.Queueable;
|
import org.logstash.ackedqueue.Queueable;
|
||||||
import org.logstash.ext.JrubyEventExtLibrary;
|
import org.logstash.ext.JrubyEventExtLibrary;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class JrubyAckedBatchExtLibrary implements Library {
|
public final class JrubyAckedBatchExtLibrary implements Library {
|
||||||
|
@ -84,7 +83,7 @@ public final class JrubyAckedBatchExtLibrary implements Library {
|
||||||
try {
|
try {
|
||||||
this.batch.close();
|
this.batch.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw context.runtime.newIOErrorFromException(e);
|
throw RubyUtil.newRubyIOError(context.runtime, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.nil;
|
return context.nil;
|
||||||
|
|
|
@ -128,7 +128,7 @@ public final class JrubyAckedQueueExtLibrary implements Library {
|
||||||
try {
|
try {
|
||||||
this.queue.open();
|
this.queue.open();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw context.runtime.newIOErrorFromException(e);
|
throw RubyUtil.newRubyIOError(context.runtime, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.nil;
|
return context.nil;
|
||||||
|
@ -145,7 +145,7 @@ public final class JrubyAckedQueueExtLibrary implements Library {
|
||||||
try {
|
try {
|
||||||
seqNum = this.queue.write(((JrubyEventExtLibrary.RubyEvent) event).getEvent());
|
seqNum = this.queue.write(((JrubyEventExtLibrary.RubyEvent) event).getEvent());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw context.runtime.newIOErrorFromException(e);
|
throw RubyUtil.newRubyIOError(context.runtime, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.runtime.newFixnum(seqNum);
|
return context.runtime.newFixnum(seqNum);
|
||||||
|
@ -159,7 +159,7 @@ public final class JrubyAckedQueueExtLibrary implements Library {
|
||||||
try {
|
try {
|
||||||
b = this.queue.readBatch(RubyFixnum.num2int(limit), RubyFixnum.num2int(timeout));
|
b = this.queue.readBatch(RubyFixnum.num2int(limit), RubyFixnum.num2int(timeout));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw context.runtime.newIOErrorFromException(e);
|
throw RubyUtil.newRubyIOError(context.runtime, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: return proper Batch object
|
// TODO: return proper Batch object
|
||||||
|
@ -184,7 +184,7 @@ public final class JrubyAckedQueueExtLibrary implements Library {
|
||||||
try {
|
try {
|
||||||
this.queue.close();
|
this.queue.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw context.runtime.newIOErrorFromException(e);
|
throw RubyUtil.newRubyIOError(context.runtime, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.nil;
|
return context.nil;
|
||||||
|
|
|
@ -126,7 +126,7 @@ public final class JrubyAckedQueueMemoryExtLibrary implements Library {
|
||||||
this.queue.getCheckpointIO().purge();
|
this.queue.getCheckpointIO().purge();
|
||||||
this.queue.open();
|
this.queue.open();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw context.runtime.newIOErrorFromException(e);
|
throw RubyUtil.newRubyIOError(context.runtime, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.nil;
|
return context.nil;
|
||||||
|
@ -143,7 +143,7 @@ public final class JrubyAckedQueueMemoryExtLibrary implements Library {
|
||||||
try {
|
try {
|
||||||
seqNum = this.queue.write(((JrubyEventExtLibrary.RubyEvent) event).getEvent());
|
seqNum = this.queue.write(((JrubyEventExtLibrary.RubyEvent) event).getEvent());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw context.runtime.newIOErrorFromException(e);
|
throw RubyUtil.newRubyIOError(context.runtime, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.runtime.newFixnum(seqNum);
|
return context.runtime.newFixnum(seqNum);
|
||||||
|
@ -157,7 +157,7 @@ public final class JrubyAckedQueueMemoryExtLibrary implements Library {
|
||||||
try {
|
try {
|
||||||
b = this.queue.readBatch(RubyFixnum.num2int(limit), RubyFixnum.num2int(timeout));
|
b = this.queue.readBatch(RubyFixnum.num2int(limit), RubyFixnum.num2int(timeout));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw context.runtime.newIOErrorFromException(e);
|
throw RubyUtil.newRubyIOError(context.runtime, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: return proper Batch object
|
// TODO: return proper Batch object
|
||||||
|
@ -182,7 +182,7 @@ public final class JrubyAckedQueueMemoryExtLibrary implements Library {
|
||||||
try {
|
try {
|
||||||
this.queue.close();
|
this.queue.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw context.runtime.newIOErrorFromException(e);
|
throw RubyUtil.newRubyIOError(context.runtime, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.nil;
|
return context.nil;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue