##// END OF EJS Templates
check-code: ignore naked excepts with a "re-raise" comment...
Brodie Rao -
r16705:c2d9ef43 default
parent child Browse files
Show More
@@ -203,10 +203,10 b' pypats = ['
203 (r'(?i)descendent', "the proper spelling is descendAnt"),
203 (r'(?i)descendent', "the proper spelling is descendAnt"),
204 (r'\.debug\(\_', "don't mark debug messages for translation"),
204 (r'\.debug\(\_', "don't mark debug messages for translation"),
205 (r'\.strip\(\)\.split\(\)', "no need to strip before splitting"),
205 (r'\.strip\(\)\.split\(\)', "no need to strip before splitting"),
206 (r'^\s*except\s*:', "warning: naked except clause", r'#.*re-raises'),
206 ],
207 ],
207 # warnings
208 # warnings
208 [
209 [
209 (r'^\s*except\s*:', "warning: naked except clause"),
210 (r'ui\.(status|progress|write|note|warn)\([\'\"]x',
210 (r'ui\.(status|progress|write|note|warn)\([\'\"]x',
211 "warning: unwrapped ui message"),
211 "warning: unwrapped ui message"),
212 ]
212 ]
@@ -355,7 +355,13 b' def checkfile(f, logfunc=_defaultlogger.'
355
355
356 prelines = None
356 prelines = None
357 errors = []
357 errors = []
358 for p, msg in pats:
358 for pat in pats:
359 if len(pat) == 3:
360 p, msg, ignore = pat
361 else:
362 p, msg = pat
363 ignore = None
364
359 # fix-up regexes for multiline searches
365 # fix-up regexes for multiline searches
360 po = p
366 po = p
361 # \s doesn't match \n
367 # \s doesn't match \n
@@ -386,6 +392,8 b' def checkfile(f, logfunc=_defaultlogger.'
386 print "Skipping %s for %s:%s (check-code -ignore)" % (
392 print "Skipping %s for %s:%s (check-code -ignore)" % (
387 name, f, n)
393 name, f, n)
388 continue
394 continue
395 elif ignore and re.search(ignore, l, re.MULTILINE):
396 continue
389 bd = ""
397 bd = ""
390 if blame:
398 if blame:
391 bd = 'working directory'
399 bd = 'working directory'
@@ -240,7 +240,7 b' def shrink(ui, repo, **opts):'
240 writerevs(ui, r1, r2, order, tr)
240 writerevs(ui, r1, r2, order, tr)
241 report(ui, r1, r2)
241 report(ui, r1, r2)
242 tr.close()
242 tr.close()
243 except:
243 except: # re-raises
244 # Abort transaction first, so we truncate the files before
244 # Abort transaction first, so we truncate the files before
245 # deleting them.
245 # deleting them.
246 tr.abort()
246 tr.abort()
@@ -712,7 +712,7 b' class queue(object):'
712 tr.close()
712 tr.close()
713 self.savedirty()
713 self.savedirty()
714 return 2, repo.dirstate.p1()
714 return 2, repo.dirstate.p1()
715 except:
715 except: # re-raises
716 try:
716 try:
717 tr.abort()
717 tr.abort()
718 finally:
718 finally:
@@ -1077,7 +1077,7 b' class queue(object):'
1077 r = self.qrepo()
1077 r = self.qrepo()
1078 if r:
1078 if r:
1079 r[None].add([patchfn])
1079 r[None].add([patchfn])
1080 except:
1080 except: # re-raises
1081 repo.rollback()
1081 repo.rollback()
1082 raise
1082 raise
1083 except Exception:
1083 except Exception:
@@ -1303,7 +1303,7 b' class queue(object):'
1303 else:
1303 else:
1304 ret = self.apply(repo, s, list, all_files=all_files,
1304 ret = self.apply(repo, s, list, all_files=all_files,
1305 tobackup=tobackup, check=check)
1305 tobackup=tobackup, check=check)
1306 except:
1306 except: # re-raises
1307 self.ui.warn(_('cleaning up working directory...'))
1307 self.ui.warn(_('cleaning up working directory...'))
1308 node = repo.dirstate.p1()
1308 node = repo.dirstate.p1()
1309 hg.revert(repo, node, None)
1309 hg.revert(repo, node, None)
@@ -1629,7 +1629,7 b' class queue(object):'
1629 self.applieddirty = True
1629 self.applieddirty = True
1630 self.strip(repo, [top], update=False,
1630 self.strip(repo, [top], update=False,
1631 backup='strip')
1631 backup='strip')
1632 except:
1632 except: # re-raises
1633 repo.dirstate.invalidate()
1633 repo.dirstate.invalidate()
1634 raise
1634 raise
1635
1635
@@ -1643,7 +1643,7 b' class queue(object):'
1643 # only write patch after a successful commit
1643 # only write patch after a successful commit
1644 patchf.close()
1644 patchf.close()
1645 self.applied.append(statusentry(n, patchfn))
1645 self.applied.append(statusentry(n, patchfn))
1646 except:
1646 except: # re-raises
1647 ctx = repo[cparents[0]]
1647 ctx = repo[cparents[0]]
1648 repo.dirstate.rebuild(ctx.node(), ctx.manifest())
1648 repo.dirstate.rebuild(ctx.node(), ctx.manifest())
1649 self.savedirty()
1649 self.savedirty()
@@ -3775,7 +3775,7 b' def import_(ui, repo, patch1=None, *patc'
3775 tr.close()
3775 tr.close()
3776 if msgs:
3776 if msgs:
3777 repo.savecommitmessage('\n* * *\n'.join(msgs))
3777 repo.savecommitmessage('\n* * *\n'.join(msgs))
3778 except:
3778 except: # re-raises
3779 # wlock.release() indirectly calls dirstate.write(): since
3779 # wlock.release() indirectly calls dirstate.write(): since
3780 # we're crashing, we do not want to change the working dir
3780 # we're crashing, we do not want to change the working dir
3781 # parent after all, so make sure it writes nothing
3781 # parent after all, so make sure it writes nothing
@@ -88,7 +88,7 b' def _runcatch(req):'
88 return _dispatch(req)
88 return _dispatch(req)
89 finally:
89 finally:
90 ui.flush()
90 ui.flush()
91 except:
91 except: # re-raises
92 # enter the debugger when we hit an exception
92 # enter the debugger when we hit an exception
93 if '--debugger' in req.args:
93 if '--debugger' in req.args:
94 traceback.print_exc()
94 traceback.print_exc()
@@ -204,7 +204,7 b' def _runcatch(req):'
204 return inst.code
204 return inst.code
205 except socket.error, inst:
205 except socket.error, inst:
206 ui.warn(_("abort: %s\n") % inst.args[-1])
206 ui.warn(_("abort: %s\n") % inst.args[-1])
207 except:
207 except: # re-raises
208 ui.warn(_("** unknown exception encountered,"
208 ui.warn(_("** unknown exception encountered,"
209 " please report by visiting\n"))
209 " please report by visiting\n"))
210 ui.warn(_("** http://mercurial.selenic.com/wiki/BugTracker\n"))
210 ui.warn(_("** http://mercurial.selenic.com/wiki/BugTracker\n"))
@@ -203,7 +203,7 b' def copystore(ui, srcrepo, destpath):'
203 else:
203 else:
204 ui.debug("copied %d files\n" % num)
204 ui.debug("copied %d files\n" % num)
205 return destlock
205 return destlock
206 except:
206 except: # re-raises
207 release(destlock)
207 release(destlock)
208 raise
208 raise
209
209
@@ -290,7 +290,7 b' class KeepAliveHandler(object):'
290 # worked. We'll check the version below, too.
290 # worked. We'll check the version below, too.
291 except (socket.error, httplib.HTTPException):
291 except (socket.error, httplib.HTTPException):
292 r = None
292 r = None
293 except:
293 except: # re-raises
294 # adding this block just in case we've missed
294 # adding this block just in case we've missed
295 # something we will still raise the exception, but
295 # something we will still raise the exception, but
296 # lets try and close the connection and remove it
296 # lets try and close the connection and remove it
@@ -1180,7 +1180,7 b' class localrepository(repo.repository):'
1180 self.hook("precommit", throw=True, parent1=hookp1,
1180 self.hook("precommit", throw=True, parent1=hookp1,
1181 parent2=hookp2)
1181 parent2=hookp2)
1182 ret = self.commitctx(cctx, True)
1182 ret = self.commitctx(cctx, True)
1183 except:
1183 except: # re-raises
1184 if edited:
1184 if edited:
1185 self.ui.write(
1185 self.ui.write(
1186 _('note: commit message saved in %s\n') % msgfn)
1186 _('note: commit message saved in %s\n') % msgfn)
@@ -245,7 +245,7 b' def extract(ui, fileobj):'
245 tmpfp.write('\n')
245 tmpfp.write('\n')
246 elif not diffs_seen and message and content_type == 'text/plain':
246 elif not diffs_seen and message and content_type == 'text/plain':
247 message += '\n' + payload
247 message += '\n' + payload
248 except:
248 except: # re-raises
249 tmpfp.close()
249 tmpfp.close()
250 os.unlink(tmpname)
250 os.unlink(tmpname)
251 raise
251 raise
@@ -131,7 +131,7 b' def strip(ui, repo, nodelist, backup="al'
131 file, troffset, ignore = tr.entries[i]
131 file, troffset, ignore = tr.entries[i]
132 repo.sopener(file, 'a').truncate(troffset)
132 repo.sopener(file, 'a').truncate(troffset)
133 tr.close()
133 tr.close()
134 except:
134 except: # re-raises
135 tr.abort()
135 tr.abort()
136 raise
136 raise
137
137
@@ -160,7 +160,7 b' def strip(ui, repo, nodelist, backup="al'
160 for m in updatebm:
160 for m in updatebm:
161 bm[m] = repo['.'].node()
161 bm[m] = repo['.'].node()
162 bookmarks.write(repo)
162 bookmarks.write(repo)
163 except:
163 except: # re-raises
164 if backupfile:
164 if backupfile:
165 ui.warn(_("strip failed, full bundle stored in '%s'\n")
165 ui.warn(_("strip failed, full bundle stored in '%s'\n")
166 % backupfile)
166 % backupfile)
@@ -760,7 +760,7 b' def mktempcopy(name, emptyok=False, crea'
760 ofp.write(chunk)
760 ofp.write(chunk)
761 ifp.close()
761 ifp.close()
762 ofp.close()
762 ofp.close()
763 except:
763 except: # re-raises
764 try: os.unlink(temp)
764 try: os.unlink(temp)
765 except OSError: pass
765 except OSError: pass
766 raise
766 raise
@@ -8,9 +8,6 b''
8 $ hg manifest | xargs "$check_code" || echo 'FAILURE IS NOT AN OPTION!!!'
8 $ hg manifest | xargs "$check_code" || echo 'FAILURE IS NOT AN OPTION!!!'
9
9
10 $ hg manifest | xargs "$check_code" --warnings --nolineno --per-file=0 || true
10 $ hg manifest | xargs "$check_code" --warnings --nolineno --per-file=0 || true
11 contrib/shrink-revlog.py:0:
12 > except:
13 warning: naked except clause
14 hgext/convert/cvsps.py:0:
11 hgext/convert/cvsps.py:0:
15 > ui.write('Ancestors: %s\n' % (','.join(r)))
12 > ui.write('Ancestors: %s\n' % (','.join(r)))
16 warning: unwrapped ui message
13 warning: unwrapped ui message
@@ -69,15 +66,6 b''
69 > ui.note("hg ci -m '%s'\n" % msg)
66 > ui.note("hg ci -m '%s'\n" % msg)
70 warning: unwrapped ui message
67 warning: unwrapped ui message
71 hgext/mq.py:0:
68 hgext/mq.py:0:
72 > except:
73 warning: naked except clause
74 hgext/mq.py:0:
75 > except:
76 warning: naked except clause
77 warning: naked except clause
78 warning: naked except clause
79 warning: naked except clause
80 hgext/mq.py:0:
81 > ui.write("mq: %s\n" % ', '.join(m))
69 > ui.write("mq: %s\n" % ', '.join(m))
82 warning: unwrapped ui message
70 warning: unwrapped ui message
83 hgext/patchbomb.py:0:
71 hgext/patchbomb.py:0:
@@ -117,9 +105,6 b''
117 > ui.write('deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas))
105 > ui.write('deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas))
118 warning: unwrapped ui message
106 warning: unwrapped ui message
119 mercurial/commands.py:0:
107 mercurial/commands.py:0:
120 > except:
121 warning: naked except clause
122 mercurial/commands.py:0:
123 > ui.write("common heads: %s\n" % " ".join([short(n) for n in common]))
108 > ui.write("common heads: %s\n" % " ".join([short(n) for n in common]))
124 warning: unwrapped ui message
109 warning: unwrapped ui message
125 mercurial/commands.py:0:
110 mercurial/commands.py:0:
@@ -177,33 +162,6 b''
177 mercurial/commands.py:0:
162 mercurial/commands.py:0:
178 > ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
163 > ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
179 warning: unwrapped ui message
164 warning: unwrapped ui message
180 mercurial/dispatch.py:0:
181 > except:
182 warning: naked except clause
183 mercurial/dispatch.py:0:
184 > except:
185 warning: naked except clause
186 mercurial/hg.py:0:
187 > except:
188 warning: naked except clause
189 mercurial/keepalive.py:0:
190 > except:
191 warning: naked except clause
192 mercurial/localrepo.py:0:
193 > except:
194 warning: naked except clause
195 mercurial/patch.py:0:
196 > except:
197 warning: naked except clause
198 mercurial/repair.py:0:
199 > except:
200 warning: naked except clause
201 mercurial/repair.py:0:
202 > except:
203 warning: naked except clause
204 mercurial/util.py:0:
205 > except:
206 warning: naked except clause
207 tests/autodiff.py:0:
165 tests/autodiff.py:0:
208 > ui.write('data lost for: %s\n' % fn)
166 > ui.write('data lost for: %s\n' % fn)
209 warning: unwrapped ui message
167 warning: unwrapped ui message
General Comments 0
You need to be logged in to leave comments. Login now