Repository: xonsh/xonsh

Issue:
When disk is full the xonsh SQLite history backend raises exception
Hi!

When disk is full the xonsh SQLite history backend raises exception and back to bash. Expected behavior is to show warning and stay working.

Exception (xonsh 0.9.26, Ubuntu 20):
<details>

```
Traceback (most recent call last):
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/main.py", line 421, in main
    sys.exit(main_xonsh(args))
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/main.py", line 459, in main_xonsh
    shell.shell.cmdloop()
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/ptk_shell/shell.py", line 344, in cmdloop
    self.default(line, raw_line)
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/base_shell.py", line 389, in default
    self._append_history(
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/base_shell.py", line 429, in _append_history
    hist.append(info)
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/history/sqlite.py", line 275, in append
    xh_sqlite_append_history(
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/history/sqlite.py", line 172, in xh_sqlite_append_history
    _xh_sqlite_insert_command(c, cmd, sessionid, store_stdout, remove_duplicates)
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/history/sqlite.py", line 123, in _xh_sqlite_insert_command
    values["frequency"] = _xh_sqlite_erase_dups(cursor, values["inp"]) + 1
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/history/sqlite.py", line 91, in _xh_sqlite_erase_dups
    cursor.execute(sql, (input,))
sqlite3.OperationalError: database or disk is full
Xonsh encountered an issue during launch
Failback to /bin/bash
(base) pc@pc:~$
```

</details>

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:
can you guide me in which file i should look for the problem?
@rijusougata13 you could start with this file `xonsh/history/sqlite.py`

Resolving patch:
diff --git a/xonsh/history/sqlite.py b/xonsh/history/sqlite.py
--- a/xonsh/history/sqlite.py
+++ b/xonsh/history/sqlite.py
@@ -193,6 +193,15 @@ def xh_sqlite_delete_items(size_to_keep, filename=None):
         return _xh_sqlite_delete_records(c, size_to_keep)
 
 
+def xh_sqlite_wipe_session(sessionid=None, filename=None):
+    """Wipe the current session's entries from the database."""
+    sql = "DELETE FROM xonsh_history WHERE sessionid = ?"
+    with _xh_sqlite_get_conn(filename=filename) as conn:
+        c = conn.cursor()
+        _xh_sqlite_create_history_table(c)
+        c.execute(sql, (str(sessionid),))
+
+
 class SqliteHistoryGC(threading.Thread):
     """Shell history garbage collection."""
 
@@ -272,13 +281,16 @@ def append(self, cmd):
         except KeyError:
             pass
         self._last_hist_inp = inp
-        xh_sqlite_append_history(
-            cmd,
-            str(self.sessionid),
-            store_stdout=envs.get("XONSH_STORE_STDOUT", False),
-            filename=self.filename,
-            remove_duplicates=("erasedups" in opts),
-        )
+        try:
+            xh_sqlite_append_history(
+                cmd,
+                str(self.sessionid),
+                store_stdout=envs.get("XONSH_STORE_STDOUT", False),
+                filename=self.filename,
+                remove_duplicates=("erasedups" in opts),
+            )
+        except sqlite3.OperationalError as err:
+            print(f"SQLite History Backend Error: {err}")
 
     def all_items(self, newest_first=False, session_id=None):
         """Display all history items."""
@@ -318,9 +330,4 @@ def clear(self):
         self.outs = []
         self.tss = []
 
-        # Wipe the current session's entries from the database.
-        sql = "DELETE FROM xonsh_history WHERE sessionid = ?"
-        with _xh_sqlite_get_conn(filename=self.filename) as conn:
-            c = conn.cursor()
-            _xh_sqlite_create_history_table(c)
-            c.execute(sql, (str(self.sessionid),))
+        xh_sqlite_wipe_session(sessionid=self.sessionid, filename=self.filename)


Test patch: