Note that there are some explanatory texts on larger screens.

plurals
  1. POExceptions in Yesod
    primarykey
    data
    text
    <p>I had made a daemon that used a very primitive form of <code>ipc</code> (telnet and send a String that had certain words in a certain order). I snapped out of it and am now using <code>JSON</code> to pass messages to a <code>Yesod</code> server. However, there were some things I really liked about my design, and I'm not sure what my choices are now.</p> <p>Here's what I was doing:</p> <pre><code>buildManager :: Phase -&gt; IO () buildManager phase = do let buildSeq = findSeq phase jid = JobID $ pack "8" config = MkConfig $ Just jid flip C.catch exceptionHandler $ runReaderT (sequence_ $ buildSeq &lt;*&gt; stages) config -- ^^ I would really like to keep the above line of code, or something like it. return () </code></pre> <p>each function in buildSeq looked like this</p> <pre><code>foo :: Stage -&gt; ReaderT Config IO () data Config = MkConfig (Either JobID Product) BaseDir JobMap </code></pre> <p><code>JobMap</code> is a <code>TMVar Map</code> that tracks information about current jobs.</p> <p>so now, what I have are Handlers, that all look like this</p> <pre><code>foo :: Handler RepJson </code></pre> <p><code>foo</code> represents a command for my daemon, each handler may have to process a different JSON object.</p> <p>What I would like to do is send one <code>JSON</code> object that represents success, and another JSON object that espresses information about some exception.</p> <p>I would like <code>foo</code>s helper function to be able to return an <code>Either</code>, but I'm not sure how I get that, plus the ability to terminate evaluation of my list of actions, <code>buildSeq</code>.</p> <p>Here's the only choice I see</p> <p>1) make sure <code>exceptionHandler</code> is in Handler. Put <code>JobMap</code> in the <code>App</code> record. Using <code>getYesod</code> alter the appropriate value in <code>JobMap</code> indicating details about the exception, which can then be accessed by <code>foo</code></p> <p>Is there a better way?</p> <p>What are my other choices?</p> <p>Edit: For clarity, I will explain the role of<code>Handler RepJson</code>. The server needs some way to accept commands such as <code>build</code> <code>stop</code> <code>report</code>. The client needs some way of knowing the results of these commands. I have chosen JSON as the medium with which the server and client communicate with each other. I'm using the Handler type just to manage the JSON in/out and nothing more.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload