use of org.jruby.exceptions.RaiseException in project enumerable by hraberg.
the class JRubyTest method convertedRubyProcRaisesArgumentErrorWhenCalledWithTooFewArguments.
@Test(expected = RaiseException.class)
public void convertedRubyProcRaisesArgumentErrorWhenCalledWithTooFewArguments() throws ScriptException {
Ruby ruby = Ruby.getGlobalRuntime();
try {
RubyProc proc = toProc(Lambda.λ(s, s.toUpperCase()));
proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[0]);
} catch (RaiseException e) {
assertEquals(ruby.getArgumentError(), e.getException().getType());
throw e;
}
}
use of org.jruby.exceptions.RaiseException in project nokogiri by sparklemotion.
the class XmlReader method setAndRaiseErrorsIfAny.
private IRubyObject setAndRaiseErrorsIfAny(final Ruby runtime, final RaiseException ex) throws RaiseException {
final ReaderNode currentNode = currentNode();
if (currentNode == null)
return runtime.getNil();
if (currentNode.isError()) {
RubyArray errors = (RubyArray) getInstanceVariable("@errors");
IRubyObject error = currentNode.toSyntaxError();
errors.append(error);
setInstanceVariable("@errors", errors);
throw ex != null ? ex : new RaiseException((XmlSyntaxError) error);
}
if (ex != null)
throw ex;
return this;
}
use of org.jruby.exceptions.RaiseException in project nokogiri by sparklemotion.
the class XmlSaxPushParser method native_write.
@JRubyMethod
public IRubyObject native_write(ThreadContext context, IRubyObject chunk, IRubyObject isLast) {
try {
initialize_task(context);
} catch (IOException e) {
throw context.runtime.newRuntimeError(e.getMessage());
}
final ByteArrayInputStream data = NokogiriHelpers.stringBytesToStream(chunk);
if (data == null) {
terminateTask(context);
// Nokogiri::XML::SyntaxError
throw new RaiseException(XmlSyntaxError.createXMLSyntaxError(context.runtime));
}
int errorCount0 = parserTask.getErrorCount();
if (isLast.isTrue()) {
try {
parserTask.parser.getNokogiriHandler().endDocument();
} catch (SAXException e) {
throw context.runtime.newRuntimeError(e.getMessage());
}
terminateTask(context);
} else {
try {
Future<Void> task = stream.addChunk(data);
task.get();
} catch (ClosedStreamException ex) {
// this means the stream is closed, ignore this exception
} catch (Exception e) {
throw context.runtime.newRuntimeError(e.toString());
}
}
if (!options.recover && parserTask.getErrorCount() > errorCount0) {
terminateTask(context);
throw new RaiseException(parserTask.getLastError(), true);
}
return this;
}
use of org.jruby.exceptions.RaiseException in project nokogiri by sparklemotion.
the class HtmlSaxPushParser method native_write.
@JRubyMethod
public IRubyObject native_write(ThreadContext context, IRubyObject chunk, IRubyObject isLast) {
try {
initialize_task(context);
} catch (IOException e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
final ByteArrayInputStream data = NokogiriHelpers.stringBytesToStream(chunk);
if (data == null) {
terminateTask(context);
// Nokogiri::HTML::SyntaxError
throw new RaiseException(XmlSyntaxError.createHTMLSyntaxError(context.runtime));
}
int errorCount0 = parserTask.getErrorCount();
if (isLast.isTrue()) {
IRubyObject document = invoke(context, this, "document");
invoke(context, document, "end_document");
terminateTask(context);
} else {
try {
Future<Void> task = stream.addChunk(data);
task.get();
} catch (ClosedStreamException ex) {
// this means the stream is closed, ignore this exception
} catch (Exception e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
}
if (!options.recover && parserTask.getErrorCount() > errorCount0) {
terminateTask(context);
throw new RaiseException(parserTask.getLastError(), true);
}
return this;
}
use of org.jruby.exceptions.RaiseException in project gocd by gocd.
the class XmlDomParserContext method getDocumentWithErrorsOrRaiseException.
public XmlDocument getDocumentWithErrorsOrRaiseException(ThreadContext context, RubyClass klazz, Exception ex) {
if (options.recover) {
XmlDocument xmlDocument = getInterruptedOrNewXmlDocument(context, klazz);
this.addErrorsIfNecessary(context, xmlDocument);
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
xmlSyntaxError.setException(ex);
((RubyArray) xmlDocument.getInstanceVariable("@errors")).append(xmlSyntaxError);
return xmlDocument;
} else {
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
xmlSyntaxError.setException(ex);
throw new RaiseException(xmlSyntaxError);
}
}
Aggregations