Stephen Finucane <step...@that.guru> writes: > Either catch the specific exceptions or, in two cases, remove > unnecessary error-handling code. >
Reviewed-by: Daniel Axtens <d...@axtens.net> Regards, Daniel > Signed-off-by: Stephen Finucane <step...@that.guru> > --- > v2: > - Catch 'OSError' for failing 'xmlrpc.client.Server' connection on > Python 3 > --- > patchwork/bin/pwclient | 24 ++++++++---------------- > 1 file changed, 8 insertions(+), 16 deletions(-) > > diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient > index ceccbf3f..857c8e93 100755 > --- a/patchwork/bin/pwclient > +++ b/patchwork/bin/pwclient > @@ -388,7 +388,7 @@ def patch_id_from_hash(rpc, project, hash): > # be super paranoid > try: > patch_id = int(patch_id) > - except: > + except ValueError: > sys.stderr.write("Invalid patch ID obtained from server\n") > sys.exit(1) > return patch_id > @@ -434,13 +434,11 @@ def main(): > help='''Filter by delegate (name, e-mail substring search)''' > ) > filter_parser.add_argument( > - '-n', metavar='MAX#', > - type=int, > + '-n', metavar='MAX#', type=int, > help='''Return first n results''' > ) > filter_parser.add_argument( > - '-N', metavar='MAX#', > - type=int, > + '-N', metavar='MAX#', type=int, > help='''Return last N results''' > ) > filter_parser.add_argument( > @@ -613,16 +611,10 @@ installed locales. > 'Must specify one or more update options (-a or -s)') > > if args.get('n') is not None: > - try: > - filt.add("max_count", args.get('n')) > - except: > - action_parser.error("Invalid maximum count '%s'" % args.get('n')) > + filt.add("max_count", args.get('n')) > > if args.get('N') is not None: > - try: > - filt.add("max_count", 0 - args.get('N')) > - except: > - action_parser.error("Invalid maximum count '%s'" % args.get('N')) > + filt.add("max_count", 0 - args.get('N')) > > do_signoff = args.get('signoff') > do_three_way = args.get('3way') > @@ -668,7 +660,7 @@ installed locales. > if not project_str: > try: > project_str = config.get('options', 'default') > - except: > + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): > action_parser.error( > "No default project configured in %s\n" % CONFIG_FILE) > > @@ -717,8 +709,8 @@ installed locales. > > try: > rpc = xmlrpclib.Server(url, transport=transport) > - except: > - sys.stderr.write("Unable to connect to %s\n" % url) > + except (IOError, OSError): > + sy.stderr.write("Unable to connect to %s\n" % url) > sys.exit(1) > > # It should be safe to assume hash_str is not zero, but who knows.. > -- > 2.14.3 > > _______________________________________________ > Patchwork mailing list > Patchwork@lists.ozlabs.org > https://lists.ozlabs.org/listinfo/patchwork _______________________________________________ Patchwork mailing list Patchwork@lists.ozlabs.org https://lists.ozlabs.org/listinfo/patchwork