projecthamster / hamster

GNOME time tracker
http://projecthamster.org
GNU General Public License v3.0
1.08k stars 249 forks source link

hamster won't start: "sqlite3.OperationalError: unable to open database file" #695

Closed tchwpkgorg closed 2 years ago

tchwpkgorg commented 2 years ago

First hamster start - it complains that it can't find its database, yet exits with code 0. Can't use it and it doesn't give a clue how to initialize the database, or why it doesn't do it itself.

Hamster version 3.0.2.

$ hamster Traceback (most recent call last): File "/usr/bin/hamster", line 149, in on_activate_window self._open_window(action.get_name(), data) File "/usr/bin/hamster", line 184, in _open_window self.overview_controller = Overview() File "/usr/lib/python3/dist-packages/hamster/overview.py", line 477, in init self.find_facts() File "/usr/lib/python3/dist-packages/hamster/overview.py", line 531, in find_facts self.facts = self.storage.get_facts(start, end, search_terms=search) File "/usr/lib/python3/dist-packages/hamster/client.py", line 156, in get_facts for fact in self.conn.GetFactsJSON(dbus_range, search_terms)] File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 141, in call return self._connection.call_blocking(self._named_service, File "/usr/lib/python3/dist-packages/dbus/connection.py", line 652, in call_blocking reply_message = self.send_message_with_reply_and_block( dbus.exceptions.DBusException: org.freedesktop.DBus.Python.sqlite3.OperationalError: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/dbus/service.py", line 711, in _message_cb retval = candidate_method(self, *args, **keywords) File "/usr/libexec/hamster/hamster-service", line 335, in GetFactsJSON for fact in self.get_facts(range, search_terms=search_terms)] File "/usr/lib/python3/dist-packages/hamster/storage/storage.py", line 161, in get_facts return self.get_facts(range, search_terms) File "/usr/lib/python3/dist-packages/hamster/storage/db.py", line 732, in get_facts fact_rows = self.fetchall(query, (self._unsorted_localized, File "/usr/lib/python3/dist-packages/hamster/storage/db.py", line 900, in fetchall con = self.connection File "/usr/lib/python3/dist-packages/hamster/storage/db.py", line 887, in get_connection self.con = sqlite.connect(self.db_path, detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES) sqlite3.OperationalError: unable to open database file

Traceback (most recent call last): File "/usr/bin/hamster", line 149, in on_activate_window self._open_window(action.get_name(), data) File "/usr/bin/hamster", line 184, in _open_window self.overview_controller = Overview() File "/usr/lib/python3/dist-packages/hamster/overview.py", line 477, in init self.find_facts() File "/usr/lib/python3/dist-packages/hamster/overview.py", line 531, in find_facts self.facts = self.storage.get_facts(start, end, search_terms=search) File "/usr/lib/python3/dist-packages/hamster/client.py", line 156, in get_facts for fact in self.conn.GetFactsJSON(dbus_range, search_terms)] File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 141, in call return self._connection.call_blocking(self._named_service, File "/usr/lib/python3/dist-packages/dbus/connection.py", line 652, in call_blocking reply_message = self.send_message_with_reply_and_block( dbus.exceptions.DBusException: org.freedesktop.DBus.Python.sqlite3.OperationalError: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/dbus/service.py", line 711, in _message_cb retval = candidate_method(self, *args, **keywords) File "/usr/libexec/hamster/hamster-service", line 335, in GetFactsJSON for fact in self.get_facts(range, search_terms=search_terms)] File "/usr/lib/python3/dist-packages/hamster/storage/storage.py", line 161, in get_facts return self.get_facts(range, search_terms) File "/usr/lib/python3/dist-packages/hamster/storage/db.py", line 732, in get_facts fact_rows = self.fetchall(query, (self._unsorted_localized, File "/usr/lib/python3/dist-packages/hamster/storage/db.py", line 900, in fetchall con = self.connection File "/usr/lib/python3/dist-packages/hamster/storage/db.py", line 887, in get_connection self.con = sqlite.connect(self.db_path, detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES) sqlite3.OperationalError: unable to open database file

$ echo $? 0

GeraldJansen commented 2 years ago

The logic for opening the DB is in /usr/lib/python3/dist-packages/hamster/storage/db.py in the function __init_db_file(). The database is normally created as ~/.local/share/hamster/hamster.db (unless you have modified your XDG_DATA_HOME to something other than ~/.local/share). If that doesn't exist it also looks in two legacy directories, hamster-time-tracker and hamster-applet and tries to make a hard link to ~/.local/share/hamster. If no existing hamster.db is found, a template db is copied from /usr/share/hamster/hamster.db to the default location.

Aside from checking directory and file permissions, you may be able to get more info as follows:

pkill -ef hamster.*service 2>&1 >/dev/null `
/usr/libexec/hamster/hamster-service --log=INFO &