Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107396

Re: How much sanity checking is required for function inputs?

From Ethan Furman <ethan@stoneleaf.us>
Newsgroups comp.lang.python
Subject Re: How much sanity checking is required for function inputs?
Date 2016-04-19 23:09 -0700
Message-ID <mailman.15.1461132516.12923.python-list@python.org> (permalink)
References <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us>

Show all headers | View raw


On 04/19/2016 10:51 PM, Stephen Hansen wrote:

> But that's a fuzzy question, there's no solid and clear answer. Did you
> see Ethan's response? I largely agree with his trinity:
>
> On Sun, Apr 17, 2016, at 10:26 PM, Ethan Furman wrote:
>> I sanity check for three reasons:
>>
>> 1) raise a nicer error message
>>
>> 2) keep the point of failure close to the error
>>
>> 3) the consequences of bad data are Bad Bad Things (tm)
>
> With a 4)th that exceptions aren't for users, only programmers. But
> ultimately, I'd rather a user see an exception if something weird goes
> wrong because they can send it to me and I can diagnose it and push an
> update. So I also:
>
> 4) Attempt to make sure all user errors result in user error messages,
> not exceptions.
>
> Note, 1) doesn't mean I always raise a nicer message, it means if
> "KeyError" is ambiguious or odd, I raise a better and more informative
> one. But you're getting nothing swapping out KeyError for
> Exception(lotsofwords).
>
> I use 1) more to be less 'nicer' and more, er, 'more specific'. Since I
> don't like exceptions to rise to the user level where niceness is
> needed.

Yeah, that's a better phrasing for (1); I meant more appropriate or 
informative, such as swapping an internal error (such as KeyError) for a 
more meaningful FieldNotFound error (or whatever) -- largely library 
code concerns.

--
~Ethan~

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How much sanity checking is required for function inputs? Ethan Furman <ethan@stoneleaf.us> - 2016-04-19 23:09 -0700

csiph-web