Skip to content

Commit

Permalink
Make sure not to catch keyboard interrupts and system exits
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkFenX committed Feb 3, 2020
1 parent f22a4f1 commit 9ddfcc8
Show file tree
Hide file tree
Showing 42 changed files with 171 additions and 3 deletions.
2 changes: 2 additions & 0 deletions _development/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class ReadOnlyException(Exception):
gamedata_version = gamedata_session.execute(
"SELECT `field_value` FROM `metadata` WHERE `field_name` LIKE 'client_build'"
).fetchone()[0]
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
print("Missing gamedata version.")
gamedata_version = None
Expand Down
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ def defLogging():
# reset=False,
)
])
except (KeyboardInterrupt, SystemExit):
raise
except:
print("Critical error attempting to setup logging. Falling back to console only.")
logging_setup = NestedSetup([
Expand Down
4 changes: 2 additions & 2 deletions db_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def db_needs_update():
try:
with open(os.path.join(JSON_DIR, 'phobos', 'metadata.json')) as f:
data_version = next((r['field_value'] for r in json.load(f) if r['field_name'] == 'client_build'))
except KeyboardInterrupt:
except (KeyboardInterrupt, SystemExit):
raise
# If we have no source data - return None; should not update in this case
except:
Expand All @@ -61,7 +61,7 @@ def db_needs_update():
db_schema_version = int(row[0])
cursor.close()
db.close()
except KeyboardInterrupt:
except (KeyboardInterrupt, SystemExit):
raise
except:
print('Error when fetching gamedata DB metadata')
Expand Down
2 changes: 2 additions & 0 deletions eos/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class ReadOnlyException(Exception):
config.gamedata_date = gamedata_session.execute(
"SELECT `field_value` FROM `metadata` WHERE `field_name` LIKE 'dump_time'"
).fetchone()[0]
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
pyfalog.warning("Missing gamedata version.")
pyfalog.critical(e)
Expand Down
4 changes: 4 additions & 0 deletions eos/db/migrations/upgrade17.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ def upgrade(saveddata_engine):
try:
saveddata_session.execute(commandFits_table.insert(),
{"boosterID": value, "boostedID": boosted, "active": 1})
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
pass
saveddata_session.commit()
except (KeyboardInterrupt, SystemExit):
raise
except:
# Shouldn't fail unless you have updated database without the old fleet schema and manually modify the database version
# If it does, simply fail. Fleet data migration isn't critically important here
Expand Down
2 changes: 2 additions & 0 deletions eos/db/migrations/upgrade25.py
Original file line number Diff line number Diff line change
Expand Up @@ -4235,6 +4235,8 @@ def upgrade(saveddata_engine):

# And last but not least, delete the last subsystem
saveddata_engine.execute("DELETE FROM modules WHERE ID = ?", (oldModules[4][0],))
except (KeyboardInterrupt, SystemExit):
raise
except:
# if something fails, fuck it, we tried. It'll default to the generic conversion below
continue
Expand Down
4 changes: 4 additions & 0 deletions eos/db/saveddata/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ def commit():
with sd_lock:
try:
saveddata_session.commit()
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
saveddata_session.rollback()
exc_info = sys.exc_info()
Expand All @@ -570,6 +572,8 @@ def flush():
with sd_lock:
try:
saveddata_session.flush()
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
saveddata_session.rollback()
exc_info = sys.exc_info()
Expand Down
2 changes: 2 additions & 0 deletions eos/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32676,6 +32676,8 @@ def handler(fit, src, context, projectionRange, **kwargs):
# via https://forums.eveonline.com/default.aspx?g=posts&t=515826
try:
bonus = max(0, min(50.0, (src.owner.character.secStatus * 10)))
except (KeyboardInterrupt, SystemExit):
raise
except:
bonus = None

Expand Down
4 changes: 4 additions & 0 deletions eos/gamedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ def __generateHandler(self):
self.__activeByDefault = True
self.__type = None
pyfalog.error("AttributeError generating handler: {0}", e)
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
self.__handler = eos.effects.DummyEffect.handler
self.__runTime = "normal"
Expand All @@ -200,6 +202,8 @@ def getattr(self, key):

try:
return self.__effectDef.get(key, None)
except (KeyboardInterrupt, SystemExit):
raise
except:
return getattr(self.__effectDef, key, None)

Expand Down
4 changes: 4 additions & 0 deletions eos/saveddata/damagePattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ def importPatterns(cls, text):
line = line.split('#', 1)[0] # allows for comments
type, data = line.rsplit('=', 1)
type, data = type.strip(), data.split(',')
except (KeyboardInterrupt, SystemExit):
raise
except:
# Data isn't in correct format, continue to next line
continue
Expand All @@ -274,6 +276,8 @@ def importPatterns(cls, text):
for index, val in enumerate(data):
try:
fields["%sAmount" % cls.DAMAGE_TYPES[index]] = int(val)
except (KeyboardInterrupt, SystemExit):
raise
except:
continue

Expand Down
2 changes: 2 additions & 0 deletions eos/saveddata/mutator.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def build(self):
self.dynamicAttribute = next(a for a in self.module.mutaplasmid.attributes if a.attributeID == self.attrID)
# base attribute links to the base ite's attribute for this mutated definition (contains original, base value)
self.baseAttribute = self.module.item.attributes[self.dynamicAttribute.name]
except (KeyboardInterrupt, SystemExit):
raise
except:
self.module = None

Expand Down
4 changes: 4 additions & 0 deletions eos/saveddata/targetProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ def importPatterns(cls, text):
line = line.split('#', 1)[0] # allows for comments
type, data = line.rsplit('=', 1)
type, data = type.strip(), [d.strip() for d in data.split(',')]
except (KeyboardInterrupt, SystemExit):
raise
except:
pyfalog.warning("Data isn't in correct format, continue to next line.")
continue
Expand All @@ -312,6 +314,8 @@ def importPatterns(cls, text):
try:
assert 0 <= val <= 100
fields["%sAmount" % cls.DAMAGE_TYPES[index]] = val / 100
except (KeyboardInterrupt, SystemExit):
raise
except:
pyfalog.warning("Caught unhandled exception in import patterns.")
continue
Expand Down
8 changes: 8 additions & 0 deletions graphs/gui/canvasPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
except ImportError as e:
pyfalog.warning('Matplotlib failed to import. Likely missing or incompatible version.')
graphFrame_enabled = False
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
# We can get exceptions deep within matplotlib. Catch those. See GH #1046
tb = traceback.format_exc()
Expand All @@ -71,6 +73,8 @@ def __init__(self, graphFrame, parent):
# Remove matplotlib font cache, see #234
try:
cache_dir = mpl._get_cachedir()
except (KeyboardInterrupt, SystemExit):
raise
except:
cache_dir = os.path.expanduser(os.path.join('~', '.matplotlib'))
cache_file = os.path.join(cache_dir, 'fontList.cache')
Expand Down Expand Up @@ -168,6 +172,8 @@ def draw(self, accurateMarks=True):
legendData.append((color, lineStyle, source.shortName))
else:
legendData.append((color, lineStyle, '{} vs {}'.format(source.shortName, target.shortName)))
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
pyfalog.warning('Failed to plot "{}" vs "{}"'.format(source.name, '' if target is None else target.name))
self.canvas.draw()
Expand Down Expand Up @@ -241,6 +247,8 @@ def addYMark(val):
src=source,
tgt=target)
addYMark(y)
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
pyfalog.warning('Failed to get X mark for "{}" vs "{}"'.format(source.name, '' if target is None else target.name))
# Silently skip this mark, otherwise other marks and legend display will fail
Expand Down
2 changes: 2 additions & 0 deletions gui/builtinItemStatsViews/itemAffectedBy.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def ExpandCollapseTree(self):
else:
try:
self.affectedBy.CollapseAll()
except (KeyboardInterrupt, SystemExit):
raise
except:
pass

Expand Down
2 changes: 2 additions & 0 deletions gui/builtinItemStatsViews/itemProperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def PopulateList(self):
valueUnit = str(value)

self.paramList.SetItem(index, 1, valueUnit)
except (KeyboardInterrupt, SystemExit):
raise
except:
# TODO: Add logging to this.
# We couldn't get a property for some reason. Skip it for now.
Expand Down
2 changes: 2 additions & 0 deletions gui/builtinMarketBrowser/marketTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def expandLookup(self, event):
iconId = self.addImage(sMkt.getIconByMarketGroup(childMktGrp))
try:
childId = self.AppendItem(root, childMktGrp.name, iconId, data=childMktGrp.ID)
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
pyfalog.debug("Error appending item.")
pyfalog.debug(e)
Expand Down
6 changes: 6 additions & 0 deletions gui/builtinViews/fittingView.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def fitSelected(self, event):
self.multiSwitch.SetSelection(index)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitIDs=(event.fitID,)))
break
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
pyfalog.critical("Caught exception in fitSelected")
pyfalog.critical(e)
Expand Down Expand Up @@ -812,6 +814,8 @@ def OnShow(self, event):
if self and not self.IsShown():
try:
self.MakeSnapshot()
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
pyfalog.critical("Failed to make snapshot")
pyfalog.critical(e)
Expand All @@ -837,6 +841,8 @@ def MakeSnapshot(self, maxColumns=1337):
sFit = Fit.getInstance()
try:
fit = sFit.getFit(self.activeFitID)
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
pyfalog.critical("Failed to get fit")
pyfalog.critical(e)
Expand Down
2 changes: 2 additions & 0 deletions gui/characterEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ def importSkills(self, evt):
if skill:
skill.setLevel(level, ignoreRestrict=True)

except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
pyfalog.error(e)
with wx.MessageDialog(self, "There was an error importing skills, please see log file", "Error", wx.ICON_ERROR) as dlg:
Expand Down
2 changes: 2 additions & 0 deletions gui/chrome_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,8 @@ def CheckTabPreview(self, mposx, mposy):
self.preview_tab = tab
self.preview_timer.Start(500, True)
break
except (KeyboardInterrupt, SystemExit):
raise
except:
pass

Expand Down
8 changes: 8 additions & 0 deletions gui/esiFittings.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def fetchFittings(self, event):
# Can't do this in a finally because then it obscures the message dialog
del waitDialog # noqa: F821
ESIExceptionHandler(self, ex)
except (KeyboardInterrupt, SystemExit):
raise
except Exception as ex:
del waitDialog # noqa: F821
raise ex
Expand Down Expand Up @@ -302,6 +304,8 @@ def exportFitting(self, event):
except APIException as ex:
try:
ESIExceptionHandler(self, ex)
except (KeyboardInterrupt, SystemExit):
raise
except Exception as ex:
self.statusbar.SetStatusText("ERROR", 0)
self.statusbar.SetStatusText("{} - {}".format(res.status_code, res.reason), 1)
Expand Down Expand Up @@ -381,6 +385,8 @@ def addChar(self, event):
try:
sEsi = Esi.getInstance()
sEsi.login()
except (KeyboardInterrupt, SystemExit):
raise
except Exception as ex:
ESIServerExceptionHandler(self, ex)

Expand Down Expand Up @@ -457,6 +463,8 @@ def displayFit(self, event):
cargo = Cargo(getItem(item['type_id']))
cargo.amount = item['quantity']
list.append(cargo)
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
pyfalog.critical("Exception caught in displayFit")
pyfalog.critical(e)
Expand Down
4 changes: 4 additions & 0 deletions gui/mainFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ def LoadPreviousOpenFits(self):
fit = sFit.getFit(id, basic=True)
if fit is None:
fits.remove(id)
except (KeyboardInterrupt, SystemExit):
raise
except:
fits.remove(id)

Expand Down Expand Up @@ -774,6 +776,8 @@ def importFromClipboard(self, event):
if self.command.Submit(cmd.GuiImportCargosCommand(activeFit, [(i.ID, a) for i, a in importData[0]])):
self.additionsPane.select("Cargo")
return
except (KeyboardInterrupt, SystemExit):
raise
except:
pyfalog.error("Attempt to import failed:\n{0}", clipboard)
else:
Expand Down
2 changes: 2 additions & 0 deletions gui/patternEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ def importPatterns(self, event):
except ImportError as e:
pyfalog.error(e)
self.stNotice.SetLabel(str(e))
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
msg = "Could not import from clipboard: unknown errors"
pyfalog.warning(msg)
Expand Down
2 changes: 2 additions & 0 deletions gui/setEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ def importPatterns(self, event):
except ImportError as e:
pyfalog.error(e)
self.stNotice.SetLabel(str(e))
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
pyfalog.error(e)
self.stNotice.SetLabel("Could not import from clipboard: unknown errors")
Expand Down
2 changes: 2 additions & 0 deletions gui/targetProfileEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ def importPatterns(self, event):
except ImportError as e:
pyfalog.error(e)
self.stNotice.SetLabel(str(e))
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
msg = "Could not import from clipboard:"
pyfalog.warning(msg)
Expand Down
6 changes: 6 additions & 0 deletions gui/utils/exportHtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def run(self):
except IOError as ex:
pyfalog.warning("Failed to write to " + settings.getPath())
pass
except (KeyboardInterrupt, SystemExit):
raise
except Exception as ex:
pass

Expand Down Expand Up @@ -226,6 +228,8 @@ def generateFullHTML(self, sMkt, sFit, dnaUrl):

HTMLfit += ' </ul>\n </li>\n'
HTMLship += HTMLfit
except (KeyboardInterrupt, SystemExit):
raise
except:
pyfalog.warning("Failed to export line")
continue
Expand Down Expand Up @@ -281,6 +285,8 @@ def generateMinimalHTML(self, sMkt, sFit, dnaUrl):
HTML += '<a class="outOfGameBrowserLink" target="_blank" href="' + dnaUrl + dnaFit + '">' \
+ ship.name + ': ' + \
fit[1] + '</a><br> \n'
except (KeyboardInterrupt, SystemExit):
raise
except:
pyfalog.error("Failed to export line")
continue
Expand Down
2 changes: 1 addition & 1 deletion scripts/effectUsedBy.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def calc_outerscore(innerscore_dict, pereffect_totalaffected, weight):
def validate_string(s):
try:
s.encode('ascii')
except KeyboardInterrupt:
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
return False
Expand Down
2 changes: 2 additions & 0 deletions scripts/itemDiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ def getattrname(attr):
new_cursor.execute(query)
for row in new_cursor:
new_meta[row[0]] = row[1]
except (KeyboardInterrupt, SystemExit):
raise
except:
pass
# Print jobs
Expand Down
Loading

0 comments on commit 9ddfcc8

Please sign in to comment.