Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Reading, Processing, and Writing I/O (Dananji Liyanage)
   2. Re:  AMQP and nested exception handlers (Alex)
   3. Re:  AMQP and nested exception handlers (Alexey Shmalko)
   4. Re:  AMQP and nested exception handlers (Alex)
   5. Re:  AMQP and nested exception handlers (Alexey Shmalko)


----------------------------------------------------------------------

Message: 1
Date: Tue, 12 May 2015 10:46:27 +0530
From: Dananji Liyanage <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Reading, Processing, and Writing I/O
Message-ID:
        <CAAPsY8yDP1Bpo3W=KjYZQ0eRXqfPVH1j=XQVLdjVFg=hhmv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thank you :)

On Tue, May 12, 2015 at 10:42 AM, Kim-Ee Yeoh <[email protected]> wrote:

>
> On Tue, May 12, 2015 at 10:47 AM, Dananji Liyanage <[email protected]>
> wrote:
>
> reverseInput input = (last input) : reverseInput (init input)
>
>
> This won't terminate. That's the bug.
>
> -- Kim-Ee
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>


-- 
Regards,
Dananji Liyanage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150512/70f4f59b/attachment-0001.html>

------------------------------

Message: 2
Date: Tue, 12 May 2015 01:23:22 -0400
From: Alex <[email protected]>
To: Kostiantyn Rybnikov <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] AMQP and nested exception handlers
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Tue, 12 May 2015 08:15:28 +0300
Kostiantyn Rybnikov <[email protected]> wrote:

> Hi.
> 
> I would suggest to separate data-extraction from request stage and
> data-sending one. Create a data-structure that will represent a thing
> you will want to send into RabbitMQ, and build it before you send
> anything. Then catch exceptions in IO-based layer to handle exception
> case.
> 
> This way you won't need any evaluation tricks and will get all
> exceptions during that phase.
> 

In my case, the HTTP request is immediately parsed and a data structure
representing the request is created. The request is forwarded to the
AMQP code which does the following:

    publishMsg chan "" "the-queue"
      newMsg { msgDeliveryMode = Just Persistent
             , msgReplyTo      = Just cbQueue
             , msgBody         = encode req
             }

where "encode req" uses aeson to transform the data structure in to
JSON.

I tried to make the values which comprise the request data structure
strict (by prefixing them with `!'), but it does not seem to help.

> Cheers.
>  12 ????. 2015 05:11 "Alex" <[email protected]> ????:
> 
> > Hi:
> >
> > I am writing a small application which receives HTTP requests,
> > translates them to JSON, and queues the requests using RabbitMQ.
> >
> > I am using exceptions to handle extreme cases, such as when a
> > client's HTTP request lacks a critical header:
> >
> > lookupHeader :: RequestHeaders -> HeaderName -> Text
> > lookupHeader hs h = decodeUtf8 $ fromMaybe notFound
> >                                            (lookup h hs)
> >   where
> >     notFound = throw $ MissingHeader $ decodeUtf8 $ original h
> >
> > The problem I am running in to is that the header isn't actually
> > looked up until I call the AMQP library's publishMsg function. If I
> > purposely do not supply a critical header, I get the following
> > error printed to the screen:
> >
> > ConnectionClosedException "ConnectionClosedException
> > \"UNEXPECTED_FRAME
> > - expected content header for class 60, got non content header frame
> > instead\""
> >
> > If I add the following line just above the publishMsg function (to
> > force evaluation), my exception handler is called successfully:
> >
> > print $ encode req
> >
> > As a result, I suspect that this is due to the fact that the "throw
> > MissingHeader" is getting captured by the AMQP library. What's the
> > best way to deal with this situation?
> >
> > --
> > Alex
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >



-- 
Alex


------------------------------

Message: 3
Date: Tue, 12 May 2015 05:24:32 +0000
From: Alexey Shmalko <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] AMQP and nested exception handlers
Message-ID:
        <CAFC2PC5vreEpSkfUrm7a0GK5GBWK8VyKE-VqRZ952q=y+mj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Your issue is related to Lazy evaluation. Your function (lookupHeader)
isn't actually evaluated before you call publishMsg or print. You need to
put seq or deepseq to overcome this, or put your exception handler in place
when your function is actually evaluated. Unfortunately, you haven't
provided the calling code, so I have no specific suggestion. Just read some
info on Lazy vs. Strict.

Parallel and Concurrent Programming in Haskell Chapter 2 [1] has a good
description (just skip "The Eval Monad, rpar, and rseq" section and
continue with deepseq).
Here is a good chapter on exception [2], if you need one.

[1]: http://chimera.labs.oreilly.com/books/1230000000929/ch02.html
[2]:
http://chimera.labs.oreilly.com/books/1230000000929/ch08.html#sec_exceptions

On Tue, May 12, 2015 at 5:11 AM Alex <[email protected]> wrote:

> Hi:
>
> I am writing a small application which receives HTTP requests,
> translates them to JSON, and queues the requests using RabbitMQ.
>
> I am using exceptions to handle extreme cases, such as when a client's
> HTTP request lacks a critical header:
>
> lookupHeader :: RequestHeaders -> HeaderName -> Text
> lookupHeader hs h = decodeUtf8 $ fromMaybe notFound
>                                            (lookup h hs)
>   where
>     notFound = throw $ MissingHeader $ decodeUtf8 $ original h
>
> The problem I am running in to is that the header isn't actually looked
> up until I call the AMQP library's publishMsg function. If I purposely
> do not supply a critical header, I get the following error printed to
> the screen:
>
> ConnectionClosedException "ConnectionClosedException \"UNEXPECTED_FRAME
> - expected content header for class 60, got non content header frame
> instead\""
>
> If I add the following line just above the publishMsg function (to
> force evaluation), my exception handler is called successfully:
>
> print $ encode req
>
> As a result, I suspect that this is due to the fact that the "throw
> MissingHeader" is getting captured by the AMQP library. What's the best
> way to deal with this situation?
>
> --
> Alex
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150512/50a663e9/attachment-0001.html>

------------------------------

Message: 4
Date: Tue, 12 May 2015 02:10:50 -0400
From: Alex <[email protected]>
To: Alexey Shmalko <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] AMQP and nested exception handlers
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

On Tue, 12 May 2015 05:24:32 +0000
Alexey Shmalko <[email protected]> wrote:

> Your issue is related to Lazy evaluation. Your function (lookupHeader)
> isn't actually evaluated before you call publishMsg or print. You
> need to put seq or deepseq to overcome this, or put your exception
> handler in place when your function is actually evaluated.
> Unfortunately, you haven't provided the calling code, so I have no
> specific suggestion. Just read some info on Lazy vs. Strict.
> 

Per your suggestion, I tried out deepseq, and it doesn't seem to be
working. Below is the code which sends the message to RMQ. As you've
noted, `req' is not fully evaluated at this point:

    publishMsg chan "" "the-queue"
      newMsg { msgDeliveryMode = Just Persistent
             , msgReplyTo      = Just cbQueue
             , msgBody         = encode req
             }

If I put this line above publishMsg, the problem still exists:

_ <- return $!! req

This is counter intuitive, because I would have thought that running
deepseq on req would fully evaluate it to NF, but that doesn't seem to
be the case.

> Parallel and Concurrent Programming in Haskell Chapter 2 [1] has a
> good description (just skip "The Eval Monad, rpar, and rseq" section
> and continue with deepseq).
> Here is a good chapter on exception [2], if you need one.
> 
> [1]: http://chimera.labs.oreilly.com/books/1230000000929/ch02.html
> [2]:
> http://chimera.labs.oreilly.com/books/1230000000929/ch08.html#sec_exceptions
> 
> On Tue, May 12, 2015 at 5:11 AM Alex <[email protected]> wrote:
> 
> > Hi:
> >
> > I am writing a small application which receives HTTP requests,
> > translates them to JSON, and queues the requests using RabbitMQ.
> >
> > I am using exceptions to handle extreme cases, such as when a
> > client's HTTP request lacks a critical header:
> >
> > lookupHeader :: RequestHeaders -> HeaderName -> Text
> > lookupHeader hs h = decodeUtf8 $ fromMaybe notFound
> >                                            (lookup h hs)
> >   where
> >     notFound = throw $ MissingHeader $ decodeUtf8 $ original h
> >
> > The problem I am running in to is that the header isn't actually
> > looked up until I call the AMQP library's publishMsg function. If I
> > purposely do not supply a critical header, I get the following
> > error printed to the screen:
> >
> > ConnectionClosedException "ConnectionClosedException
> > \"UNEXPECTED_FRAME
> > - expected content header for class 60, got non content header frame
> > instead\""
> >
> > If I add the following line just above the publishMsg function (to
> > force evaluation), my exception handler is called successfully:
> >
> > print $ encode req
> >
> > As a result, I suspect that this is due to the fact that the "throw
> > MissingHeader" is getting captured by the AMQP library. What's the
> > best way to deal with this situation?
> >
> > --
> > Alex
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >



-- 
Alex


------------------------------

Message: 5
Date: Tue, 12 May 2015 06:25:44 +0000
From: Alexey Shmalko <[email protected]>
To: Alex <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] AMQP and nested exception handlers
Message-ID:
        <CAFC2PC76c2bQN-ktaGvO=J9R=9p4hjz-bnbf63a7sqvdvtu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Seems, that you're putting it in the wrong place. Please, publish your code
to lpaste [1].

Hmm.... Maybe you need evaluate `encode req`?

On Tue, May 12, 2015 at 9:10 AM Alex <[email protected]> wrote:

> On Tue, 12 May 2015 05:24:32 +0000
> Alexey Shmalko <[email protected]> wrote:
>
> > Your issue is related to Lazy evaluation. Your function (lookupHeader)
> > isn't actually evaluated before you call publishMsg or print. You
> > need to put seq or deepseq to overcome this, or put your exception
> > handler in place when your function is actually evaluated.
> > Unfortunately, you haven't provided the calling code, so I have no
> > specific suggestion. Just read some info on Lazy vs. Strict.
> >
>
> Per your suggestion, I tried out deepseq, and it doesn't seem to be
> working. Below is the code which sends the message to RMQ. As you've
> noted, `req' is not fully evaluated at this point:
>
>     publishMsg chan "" "the-queue"
>       newMsg { msgDeliveryMode = Just Persistent
>              , msgReplyTo      = Just cbQueue
>              , msgBody         = encode req
>              }
>
> If I put this line above publishMsg, the problem still exists:
>
> _ <- return $!! req
>
> This is counter intuitive, because I would have thought that running
> deepseq on req would fully evaluate it to NF, but that doesn't seem to
> be the case.
>
> > Parallel and Concurrent Programming in Haskell Chapter 2 [1] has a
> > good description (just skip "The Eval Monad, rpar, and rseq" section
> > and continue with deepseq).
> > Here is a good chapter on exception [2], if you need one.
> >
> > [1]: http://chimera.labs.oreilly.com/books/1230000000929/ch02.html
> > [2]:
> >
> http://chimera.labs.oreilly.com/books/1230000000929/ch08.html#sec_exceptions
> >
> > On Tue, May 12, 2015 at 5:11 AM Alex <[email protected]> wrote:
> >
> > > Hi:
> > >
> > > I am writing a small application which receives HTTP requests,
> > > translates them to JSON, and queues the requests using RabbitMQ.
> > >
> > > I am using exceptions to handle extreme cases, such as when a
> > > client's HTTP request lacks a critical header:
> > >
> > > lookupHeader :: RequestHeaders -> HeaderName -> Text
> > > lookupHeader hs h = decodeUtf8 $ fromMaybe notFound
> > >                                            (lookup h hs)
> > >   where
> > >     notFound = throw $ MissingHeader $ decodeUtf8 $ original h
> > >
> > > The problem I am running in to is that the header isn't actually
> > > looked up until I call the AMQP library's publishMsg function. If I
> > > purposely do not supply a critical header, I get the following
> > > error printed to the screen:
> > >
> > > ConnectionClosedException "ConnectionClosedException
> > > \"UNEXPECTED_FRAME
> > > - expected content header for class 60, got non content header frame
> > > instead\""
> > >
> > > If I add the following line just above the publishMsg function (to
> > > force evaluation), my exception handler is called successfully:
> > >
> > > print $ encode req
> > >
> > > As a result, I suspect that this is due to the fact that the "throw
> > > MissingHeader" is getting captured by the AMQP library. What's the
> > > best way to deal with this situation?
> > >
> > > --
> > > Alex
> > > _______________________________________________
> > > Beginners mailing list
> > > [email protected]
> > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > >
>
>
>
> --
> Alex
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150512/5737514e/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 83, Issue 15
*****************************************

Reply via email to