Search Haskell Channel Logs

Monday, February 20, 2017

#haskell channel featuring lambdabot, johnw, glguy, buttons840, ongy, MarcelineVQ,

buttons840 2017-02-20 12:45:46
could someone give me some feedback on my approach to wrapping some errors here? http://lpaste.net/352796 it's taken me quite awhile to get this far and I still don't have some obvious error cases covered
ongy 2017-02-20 12:54:39
3/quit
johnw 2017-02-20 12:55:01
buttons840: use decodeUtf8' if you want an Either result
buttons840 2017-02-20 12:57:05
johnw: yeah, I'm doing that now -- am i way off the mark on how I'm handling things, or is this close to how good error handling might look?
johnw 2017-02-20 12:58:18
it feels a bit heavy on the error handling, since the actual "code" is almost nothing compared to everything else; maybe ExceptT would help to lighten it up
johnw 2017-02-20 12:58:33
gotta run
buttons840 2017-02-20 12:59:22
ty
jle` 2017-02-20 13:05:02
buttons840: i think some of this might make more sense as exceptions
buttons840 2017-02-20 13:06:05
jle`: you mean just let the code throw exceptions and catch it somewhere
jle` 2017-02-20 13:06:34
not quite 'just let'; but convey the errors as exceptions instead of as Either
lpaste_ 2017-02-20 13:09:05
Buttons840 pasted "Error wrapping attempt (complete)" at http://lpaste.net/352797
buttons840 2017-02-20 13:09:44
jle`: ok, i got it working the way i originally wanted -- why do you think this api would be better using exceptions?
jle` 2017-02-20 13:10:46
you already have exceptions that can come out anyway
jle` 2017-02-20 13:11:02
so it's about drawing the line about what should go through exceptions and waht should go through Either
jle` 2017-02-20 13:11:23
typically IO processes that can fail are handled using exceptions, as a general heuristic
buttons840 2017-02-20 13:11:42
i understand -- as far as I'm aware there are no exceptions i have not accounted for, but i believe you that I have missed some
jle` 2017-02-20 13:11:59
and "pure" exceptions (giving functions inputs that don't have a defined answer) are handled using Either/Maybe
jle` 2017-02-20 13:12:36
you mentioned the exceptions you haven't accounted for in your paste
buttons840 2017-02-20 13:13:06
jle`: i accounted for the one exception (as far as im aware) i was missing in my latest code
jle` 2017-02-20 13:13:25
i'm referring to things like network errors etc.
jle` 2017-02-20 13:13:35
the user still has to handle that no matter what
buttons840 2017-02-20 13:13:48
jle`: this specific case doesn't matter, i agree with you that in general you can expect IO code to throw many kinds of exceptions
jle` 2017-02-20 13:14:02
so i guess the judgment call comes to what you want to consider IO exceptions and what you want to consider 'pure' API errors
jle` 2017-02-20 13:15:09
an HttpException's classification is sort of debatable, but i think it'd fall more into the exception camp than a pure API input error
buttons840 2017-02-20 13:16:23
jle`: even if I do want to present the exceptions using Either, it seems like using catch behind the scenes might be easier at this point
jle` 2017-02-20 13:17:22
i meant, httpexceptions might make more sense as a thrown exception than as a Left
buttons840 2017-02-20 13:18:51
this will be part of a web app, and if I get either "NotFound" or "Directory" I'll tell the user, any other errors I'll just have to give a 500 error since the user can't really do anything about them
jle` 2017-02-20 13:19:59
it's the 'Other String' case that you might have to watch out for then in that case
buttons840 2017-02-20 13:21:20
"Other String" means I'll give the user a 500 error and log the string for further investigation
buttons840 2017-02-20 13:22:22
ill have to look into exception handling more
buttons840 2017-02-20 13:22:53
does `catches` mask like `catch` does?
jle` 2017-02-20 13:23:42
ah, so 'Other' is realy '505 error'
jle` 2017-02-20 13:23:57
looks sound then
MarcelineVQ 2017-02-20 13:25:37
does catch mask?
glguy 2017-02-20 13:26:05
The masking behavior is the difference between why you use catch or try
monochrom 2017-02-20 13:26:36
IIRC catches masks just as catch does. The whole reason why catches exists.
monochrom 2017-02-20 13:26:44
Also same atomicity.
buttons840 2017-02-20 13:26:52
there is catch and catches, and then theirs try, but no tries (or trys?)
glguy 2017-02-20 13:27:03
catches exists so that exceptions raised by one of the handlers aren't caught by another
glguy 2017-02-20 13:27:47
Given that: catches io handlers = io `catch` catchesHandler handlers
glguy 2017-02-20 13:27:52
it masks the same as catch
lambdafan 2017-02-20 13:28:12
($) applies from right to left, is there an operator that applies left to right?
MarcelineVQ 2017-02-20 13:28:25
which piece of catch is responsible for the masking behavior?
MarcelineVQ 2017-02-20 13:28:30
lambdafan &
lambdafan 2017-02-20 13:28:43
is that in Lens.Micro?
MarcelineVQ 2017-02-20 13:28:51
I'm not sure right to left is what I would describe $ as though
jle` 2017-02-20 13:28:52
it's in Data.Function
lambdafan 2017-02-20 13:28:52
I know <&> is
jle` 2017-02-20 13:28:54
in base
MarcelineVQ 2017-02-20 13:28:55
Data.Function
lambdafan 2017-02-20 13:29:02
gotcha thanks
jle` 2017-02-20 13:29:11
@hoogle (&)
lambdabot 2017-02-20 13:29:15
Data.Function (&) :: a -> (a -> b) -> b
lambdabot 2017-02-20 13:29:15
Control.Lens.Lens (&) :: a -> (a -> b) -> b
lambdabot 2017-02-20 13:29:15
Control.Lens.Operators (&) :: a -> (a -> b) -> b
monochrom 2017-02-20 13:29:52
"tries" would be nice but what would its type be?
buttons840 2017-02-20 13:32:12
same as catches?
buttons840 2017-02-20 13:34:30
:t catches
lambdabot 2017-02-20 13:34:55
error:
lambdabot 2017-02-20 13:34:55
Ambiguous occurrence 'catches'
lambdabot 2017-02-20 13:34:55
It could refer to either 'Control.Exception.catches',
buttons840 2017-02-20 13:34:55
:t catches
lambdabot 2017-02-20 13:34:55
error:
lambdabot 2017-02-20 13:34:55
Ambiguous occurrence 'catches'
lambdabot 2017-02-20 13:34:55
It could refer to either 'Control.Exception.catches',
monochrom 2017-02-20 13:34:55
That can work. And then people get confused because there are two things, very different behaviour, and same type.
monochrom 2017-02-20 13:39:14
Actually fromException.
buttons840 2017-02-20 13:43:19
:t fromException
lambdabot 2017-02-20 13:43:21
Exception e => SomeException -> Maybe e
buttons840 2017-02-20 13:44:21
under what conditions would fromException evaluate to Nothing?
jle` 2017-02-20 13:44:37
buttons840: you can think of SomeException as a sum type containing constructors for every instance of Exception
monochrom 2017-02-20 13:44:46
When you chose the wrong type for e.
jle` 2017-02-20 13:44:49
data SomeExcption = SEIO IOExcepetion | SEBlah BlahException
jle` 2017-02-20 13:45:03
it'll return 'Maybe' if you ask for an IOException, but it actually contained a BlahException