turtle icon indicating copy to clipboard operation
turtle copied to clipboard

Abstracting command return types

Open dpren opened this issue 7 years ago • 2 comments

I'm finding my code is doing a lot of this:

o1 <- shellStrict cmd1 empty
case o1 of
  (ExitFailure, stderr) -> handle err
  (ExitSuccess, stdout) -> do
    
    o2 <- shellStrict cmd2 empty
    case o2 of
      (ExitFailure, stderr) -> handle err
      (ExitSuccess, stdout) -> do

            ...

I'd like to abstract this and am wondering why Tuple is used for procStrict/shellStrict instead of the Either monad, as with inprocWithErr/inshellWithErr?

I'm not a shell programmer, so I very well may be missing the intended use case.

Here's a related discussion in the context of shell: Stack Overflow - Composing ExitCodes in Turtle.

dpren avatar Feb 08 '17 06:02 dpren

Shell supports IO, which means it supports IO exceptions. You can always throw a meaningful exception in case of ExitFailure and then catch it a few levels up.

int-index avatar Feb 08 '17 06:02 int-index

I have the same use case but I actually need to stream the result of the first command when it succeeds ... So I need to do something like inshell cmd empty & shell jq but I want to retry to first command in case of a 'ExitFailure'.

I don't see how I can achieve this without using shellStrict. Any idea ?

PierreR avatar Apr 15 '17 16:04 PierreR