1
0
mirror of https://github.com/gryf/pythonhelper.git synced 2025-12-18 12:00:27 +01:00

Get rid of catch-everything exception mechanism.

It seams, that entire block for looking for tags has been closed between
try:except keywords, catching all the exceptions, which is not necessary just
for iterating all over the file looking for particular pattern. Remove it
until real problem appear on wild - for sure I will extensively test that ;).
This commit is contained in:
2016-05-19 21:24:22 +02:00
parent 03f3c9ef1e
commit d8a44e8439

View File

@@ -111,7 +111,8 @@ class SimplePythonTagsParser(object):
"""
Computes the indentation level from the specified string.
indent_chars -- white space before any other character on line
:param indent_chars: White space before any other character on line
:returns: indent level as an int
"""
indent_level = 0
@@ -136,6 +137,7 @@ class SimplePythonTagsParser(object):
current tag
:param tag_name: short name of the current tag
:param obj_type: one of 'class' or 'def'
:returns: PythonTag object
"""
indent_level = self.compute_indentation_level(indent_chars)
parent_tag = self.get_parent_tag(tags_stack)
@@ -207,14 +209,13 @@ class PythonHelper(object):
changed_tick -- always-increasing number used to indicate that the
buffer has been modified since the last time
"""
try:
# get the tag data for the current buffer
tag_line_numbers, tags = get_tags(buffer_number, changed_tick)
# link to Vim's internal data
current_buffer = vim.current.buffer
current_window = vim.current.window
row, col = current_window.cursor
row = current_window.cursor[0]
# get the index of the nearest line
nearest_line_index = get_nearest_line_index(row, tag_line_numbers)
@@ -281,7 +282,8 @@ class PythonHelper(object):
tag_description_tag = ""
tag_description_type = ""
# if an applicable tag has been found, set the description accordingly
# if an applicable tag has been found, set the description
# accordingly
if nearest_line_number > -1:
tag_info = tags[nearest_line_number]
tag_description_tag = tag_info.full_name
@@ -289,33 +291,11 @@ class PythonHelper(object):
tag_description = "%s (%s)" % (tag_description_tag,
tag_description_type)
# update the variable for the status line so it get updated with the
# new description
vim.command("let w:PHStatusLine=\"%s\"" % (tag_description,))
vim.command("let w:PHStatusLineTag=\"%s\"" % (tag_description_tag,))
vim.command("let w:PHStatusLineType=\"%s\"" % (tag_description_type,))
# handle possible exceptions
except Exception:
# FIXME: wrap try/except blocks around single sources of exceptions
# ONLY. Break this try/except block into as many small ones as you
# need, and only catch classes of exceptions that you have encountered.
# Catching "Exception" is very, very bad style!
# To the author: why is this clause here? There's no git log for why you
# have added it. Can you please put in a comment of a specific situation
# where you have encountered exceptions?
# bury into the traceback
ec, ei, tb = sys.exc_info()
while tb is not None:
if tb.tb_next is None:
break
tb = tb.tb_next
# spit out the error
print "ERROR: %s %s %s:%u" % (ec.__name__, ei,
tb.tb_frame.f_code.co_filename,
tb.tb_lineno)
time.sleep(0.5)
# update the variable for the status line so it get updated with
# the new description
vim.command("let w:PHStatusLine=\"%s\"" % tag_description)
vim.command("let w:PHStatusLineTag=\"%s\"" % tag_description_tag)
vim.command("let w:PHStatusLineType=\"%s\"" % tag_description_type)
@classmethod
def delete_tags(cls, buffer_number):