[akka-streams-java] Exception in completionstage handling disappears without a trace

32 views
Skip to first unread message

murtuza chhil

unread,
Oct 18, 2016, 1:42:35 AM10/18/16
to Akka User List
Hi,

Just some simple java code to learn some basics of materialized values.
There is an intentional error in the code snippet  in the String.format that uses an invalid %l which actually throws an exception but nothing gets printed in the console.
What exactly is happening and how does one handle a scenarios like this to actually see/debug the exception?

public class Sample {

    public static void main(String[] args) throws IOException{

        ActorSystem system = ActorSystem.create("system");
        ActorMaterializer mat = ActorMaterializer.create(system);

        Source<ByteString, CompletionStage<IOResult>> source = FileIO.fromFile(new File("blah.txt"));

        Sink<ByteString, CompletionStage<IOResult>> sink = FileIO.toFile(new File("c:\\temp\\blah.txt.copy"));

        RunnableGraph<CompletionStage<IOResult>>  runnableGraph = source.to(sink);

        //RunnableGraph<CompletionStage<IOResult>> runnableGraph1 = source.toMat(sink, Keep.left());

        //RunnableGraph<CompletionStage<IOResult>> runnableGraph2 = source.toMat(sink, Keep.right());

        //RunnableGraph<Pair<CompletionStage<IOResult>, CompletionStage<IOResult>>> pairRunnableGraph = source.toMat(sink, Keep.both());

        final CompletionStage<IOResult> cs = runnableGraph.run(mat).handle((x, t) -> {
            if(t!=null){
                System.out.println("Error: " + t);
            }
            if (x!=null){
                String s = String.format("%s , %l bytes read",x.status(),x.count());
                System.out.println(s);
            }
            return null;
        });
-chhil
Reply all
Reply to author
Forward
0 new messages