NET-A-PORTER/scala-uri

Try(Uri.parse("%error")) still writes a traceback to stdout/stderr

Closed this issue · 2 comments

Hello,

I spent quite a lot of time trying to understand why I still get the traceback in the stdout/stderr despite I'm wrapping the call in a Try(). I just don't get it and I can't see anything in scala-uri that could possibly print this traceback.

You can reproduce it simply by using a Scala interpreter:

scala> import com.netaporter.uri.Uri
import com.netaporter.uri.Uri

scala> val x = Try(Uri.parse("%error"))
com.netaporter.uri.decoding.UriDecodeException: Encountered '%' followed by a non hex number. It looks like this URL isn't Percent Encoded. If so, look at using the NoopDecoder
        at com.netaporter.uri.decoding.PercentDecoder$.decode(PercentDecoder.scala:18)
        at com.netaporter.uri.parsing.UriParser$$anonfun$6.apply(UriParser.scala:37)
        at com.netaporter.uri.parsing.UriParser$$anonfun$6.apply(UriParser.scala:36)
        at com.netaporter.uri.parsing.DefaultUriParser._pathSegment(DefaultUriParser.scala:31)
        at com.netaporter.uri.parsing.DefaultUriParser.rec$16(DefaultUriParser.scala:46)
        at com.netaporter.uri.parsing.DefaultUriParser._rel_path(DefaultUriParser.scala:45)
        at com.netaporter.uri.parsing.DefaultUriParser._rel_uri(DefaultUriParser.scala:74)
        at com.netaporter.uri.parsing.DefaultUriParser._uri(DefaultUriParser.scala:78)
        at com.netaporter.uri.parsing.UriParser$$anonfun$10.apply(UriParser.scala:62)
        at com.netaporter.uri.parsing.UriParser$$anonfun$10.apply(UriParser.scala:62)
        at org.parboiled2.Parser.runRule$1(Parser.scala:142)
        at org.parboiled2.Parser.phase0_initialRun$1(Parser.scala:150)
        at org.parboiled2.Parser.__run(Parser.scala:203)
        at com.netaporter.uri.parsing.UriParser$.parse(UriParser.scala:62)
        at com.netaporter.uri.Uri$.parse(Uri.scala:303)
        at $line83.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$anonfun$1.apply(<console>:24)
        at $line83.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$anonfun$1.apply(<console>:24)
        at scala.util.Try$.apply(Try.scala:161)
        at $line83.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$.<init>(<console>:24)
        at $line83.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$.<clinit>(<console>)
        at $line83.$eval$.<init>(<console>:7)
        at $line83.$eval$.<clinit>(<console>)
        at $line83.$eval.$print(<console>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734)
        at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983)
        at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573)
        at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604)
        at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
        at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:760)
        at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:805)
        at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:717)
        at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:581)
        at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:588)
        at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:591)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:882)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837)
        at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
        at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:837)
        at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:904)
        at xsbt.ConsoleInterface.run(ConsoleInterface.scala:62)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:101)
        at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:76)
        at sbt.Console.sbt$Console$$console0$1(Console.scala:22)
        at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:23)
        at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:23)
        at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:23)
        at sbt.Logger$$anon$4.apply(Logger.scala:85)
        at sbt.TrapExit$App.run(TrapExit.scala:248)
        at java.lang.Thread.run(Thread.java:745)
x: scala.util.Try[com.netaporter.uri.Uri] = Failure(com.netaporter.uri.decoding.UriDecodeException: Encountered '%' followed by a non hex number. It looks like this URL isn't Percent Encoded. If so, look at using the NoopDecoder)

As you can see x is still being defined with a Failure instance, this is totally what I expect. But I just can't get rid of the traceback for some reason. I'm having this traceback during tests also (even if all the test passed).

scala> def foo(x: String): Int = x.toInt
foo: (x: String)Int

scala> val x = Try(foo("5a"))
x: scala.util.Try[Int] = Failure(java.lang.NumberFormatException: For input string: "5a")

Here I don't see any traceback. Why is it different?

I'm a beginner in Scala so I understand this issue can be due to a mistake of myself, but any hint would be really appreciated.

Thanks for your help

theon commented

Hi @cecton, thanks for raising this.

parbolied, a library scala-uri depends on was calling printStackTrace() on the exception, however this has been fixed in sirthias/parboiled2#145

I have updated to the latest parboiled and it seems to have fixed the issue. This is published as a new version 0.4.15 of scala-uri.

Try it and let me know it goes.

Yeay! It works, many thanks!