Skip to content

Commit

Permalink
fix: added catching new exceptions to history module
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 5333564790eb4e6ff657a2f679f9c7c1998c7257ba47b2f29b730bf5fd462ee1
  • Loading branch information
thindil committed Aug 19, 2023
1 parent 8b8ad71 commit 91f52e6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/history.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Standard library imports
import std/[db_sqlite, os, strutils, terminal]
# External modules imports
import contracts, nancy, termstyle
import ansiparse, contracts, nancy, termstyle
# Internal imports
import commandslist, constants, help, input, lstring, output, resultcode

Expand Down Expand Up @@ -237,7 +237,11 @@ proc showHistory*(db; arguments): ResultCode {.sideEffect, raises: [],
else:
return showError(message = "Unknown type of history sort order")
var table: TerminalTable
table.add(magenta("Last used"), magenta("Times"), magenta("Command"))
try:
table.add(magenta("Last used"), magenta("Times"), magenta("Command"))
except UnknownEscapeError, InsufficientInputError, FinalByteError:
return showError(message = "Can't show history list. Reason: ",
e = getCurrentException())
try:
for row in db.fastRows(query = sql(
query = "SELECT command, lastused, amount FROM history ORDER BY " &
Expand All @@ -248,7 +252,7 @@ proc showHistory*(db; arguments): ResultCode {.sideEffect, raises: [],
width = width + size
showFormHeader(message = "The last " & $amount &
" commands from the shell's history", width = width.ColumnAmount, db = db)
except DbError:
except DbError, UnknownEscapeError, InsufficientInputError, FinalByteError:
return showError(message = "Can't get the last commands from the shell's history. Reason: ",
e = getCurrentException())
try:
Expand Down Expand Up @@ -302,7 +306,7 @@ proc findInHistory*(db; arguments): ResultCode {.raises: [], tags: [
except IOError, Exception:
return showError(message = "Can't show the list of search results from history. Reason: ",
e = getCurrentException())
except DbError, ValueError:
except DbError, ValueError, UnknownEscapeError, InsufficientInputError, FinalByteError:
return showError(message = "Can't get the last commands from the shell's history. Reason: ",
e = getCurrentException())

Expand Down

0 comments on commit 91f52e6

Please sign in to comment.