mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
refactor errors on load
This commit is contained in:
parent
c4d30a20d9
commit
eff388974b
2 changed files with 6 additions and 20 deletions
13
anki/deck.py
13
anki/deck.py
|
@ -1574,10 +1574,11 @@ class DeckStorage(object):
|
||||||
# attach and sync/fetch deck - first, to unicode
|
# attach and sync/fetch deck - first, to unicode
|
||||||
if not isinstance(path, types.UnicodeType):
|
if not isinstance(path, types.UnicodeType):
|
||||||
path = unicode(path, sys.getfilesystemencoding())
|
path = unicode(path, sys.getfilesystemencoding())
|
||||||
|
try:
|
||||||
# sqlite needs utf8
|
# sqlite needs utf8
|
||||||
(engine, session) = DeckStorage._attach(path.encode("utf-8"), create)
|
(engine, session) = DeckStorage._attach(path.encode("utf-8"), create)
|
||||||
s = session()
|
s = session()
|
||||||
try:
|
metadata.create_all(engine)
|
||||||
if create:
|
if create:
|
||||||
deck = DeckStorage._init(s)
|
deck = DeckStorage._init(s)
|
||||||
else:
|
else:
|
||||||
|
@ -1633,9 +1634,11 @@ alter table decks add column newCount integer not null default 0""")
|
||||||
try:
|
try:
|
||||||
deck = DeckStorage._upgradeDeck(deck, path)
|
deck = DeckStorage._upgradeDeck(deck, path)
|
||||||
except:
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
deck.fixIntegrity()
|
deck.fixIntegrity()
|
||||||
deck = DeckStorage._upgradeDeck(deck, path)
|
deck = DeckStorage._upgradeDeck(deck, path)
|
||||||
except OperationalError, e:
|
except OperationalError, e:
|
||||||
|
engine.dispose()
|
||||||
if (str(e.orig).startswith("database table is locked") or
|
if (str(e.orig).startswith("database table is locked") or
|
||||||
str(e.orig).startswith("database is locked")):
|
str(e.orig).startswith("database is locked")):
|
||||||
raise DeckAccessError(_("File is in use by another process"),
|
raise DeckAccessError(_("File is in use by another process"),
|
||||||
|
@ -1659,14 +1662,6 @@ alter table decks add column newCount integer not null default 0""")
|
||||||
session = sessionmaker(bind=engine,
|
session = sessionmaker(bind=engine,
|
||||||
autoflush=False,
|
autoflush=False,
|
||||||
transactional=False)
|
transactional=False)
|
||||||
try:
|
|
||||||
metadata.create_all(engine)
|
|
||||||
except DBAPIError, e:
|
|
||||||
engine.dispose()
|
|
||||||
if create:
|
|
||||||
raise DeckAccessError(_("Can't read/write deck"))
|
|
||||||
else:
|
|
||||||
raise DeckWrongFormatError("Deck is not in the right format")
|
|
||||||
return (engine, session)
|
return (engine, session)
|
||||||
_attach = staticmethod(_attach)
|
_attach = staticmethod(_attach)
|
||||||
|
|
||||||
|
|
|
@ -19,15 +19,6 @@ class Error(Exception):
|
||||||
return m
|
return m
|
||||||
|
|
||||||
class DeckAccessError(Error):
|
class DeckAccessError(Error):
|
||||||
"The deck is empty."
|
|
||||||
pass
|
|
||||||
|
|
||||||
class DeckWrongFormatError(Error):
|
|
||||||
"A file to import is in the wrong format."
|
|
||||||
pass
|
|
||||||
|
|
||||||
class DuplicateCardError(Error):
|
|
||||||
"Attempted to add a card with the same question."
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class ImportFileError(Error):
|
class ImportFileError(Error):
|
||||||
|
|
Loading…
Reference in a new issue