Fix CommandNotFound.py crash
Contents
Issue
If an unknown command is typed, a crash message is displayed.
u505@naos:~$ unknowncommand Sorry, command-not-found has crashed! Please file a bug report at: http://www.debian.org/Bugs/Reporting Please include the following information with the report:
command-not-found version: 0.3 Python version: 3.9.1 final 0 Distributor ID: Kali Description: Kali GNU/Linux Rolling Release: 2020.4 Codename: kali-rolling Exception information:
unable to open database file Traceback (most recent call last): File "/usr/share/command-not-found/CommandNotFound/util.py", line 23, in crash_guard callback() File "/usr/lib/command-not-found", line 90, in main cnf = CommandNotFound.CommandNotFound(options.data_dir) File "/usr/share/command-not-found/CommandNotFound/CommandNotFound.py", line 79, in __init__ self.db = SqliteDatabase(dbpath) File "/usr/share/command-not-found/CommandNotFound/db/db.py", line 12, in __init__ self.con = sqlite3.connect(filename) sqlite3.OperationalError: unable to open database file
Problem
The problem is that the user doesn't have the correct rights to open the commands.db SQLite database.
u505@naos:~$ grep dbpath /usr/share/command-not-found/CommandNotFound/CommandNotFound.py
dbpath = "/var/lib/command-not-found/commands.db"
if os.path.exists(dbpath):
self.db = SqliteDatabase(dbpath)
u505@naos:~$ ls -l /var/lib/command-not-found/commands.db
-rw-r----- 1 root root 2650112 Jan 24 00:14 /var/lib/command-not-found/commands.db
Fix
Correct the databse right, to allow everybody read access.
u505@naos:~$ sudo chmod 644 /var/lib/command-not-found/commands.db
u505@naos:~$ ls -l /var/lib/command-not-found/commands.db
-rw-r--r-- 1 root root 2650112 Jan 24 00:14 /var/lib/command-not-found/commands.db
Once the file is available for users, the crash disappears.
u505@naos:~$ unknowncommand unknowncommand: command not found