[MERGE][Bug #116143] commit raises UnicodeError (traceback) if LANG is incorrect (attempt #3)

Martin Pool mbp at sourcefrog.net
Tue Aug 7 08:44:58 BST 2007


On 7/31/07, Aaron Bentley <aaron.bentley at utoronto.ca> wrote:

> > +        except UnicodeDecodeError:
> > +            f.close()
> > +            raise BzrError("specified commit message contains characters "
> > +                                        "unsupported by the current encoding")
>
> Sorry I didn't notice this earlier, but this should really be raising a
> specific exception, e.g. BadCommitMessageEncoding.  Really, the only
> place we should be raising generic exceptions is in command classes.

We should be more clear about when we want to declare a new exception
subclass rather than using a more generic one.

I used to think that we should do one for every distinguishable error
case, and basically whenever the message was different, disregarding
any runtime variables.  However, Andrew points out that declaring
new-style classes is relatively slow at import time.  So maybe we
should do it only when we expect that some code will want to
specifically catch that class, or to look at its parameters having
caught it?  That would probably not be the case here.

We could also look at getting the exception classes demand-loaded with
the code that uses them...

-- 
Martin



More information about the bazaar mailing list