Gracefully fail when history file is inaccessible (#2410)
If the history file (or its parents) can't be created, running a command will fail entirely. Since saving command history is not an integral part of running a command, it would be nicer if it carried on, just without saving history. This is what shells usually do. This patch removes assertions in the history saving function and instead adds an early return, so if the history isn't saved the command invocation simply carries on. Signed-off-by: Alyssa Ross <hi@alyssa.is>
This commit is contained in:
parent
c21e8b980a
commit
ee9670b1ea
|
@ -110,7 +110,6 @@
|
|||
-- @see string
|
||||
|
||||
-- Grab environment we need
|
||||
local assert = assert
|
||||
local io = io
|
||||
local table = table
|
||||
local math = math
|
||||
|
@ -210,8 +209,12 @@ end
|
|||
-- @param id The data.history identifier
|
||||
local function history_save(id)
|
||||
if data.history[id] then
|
||||
assert(gfs.make_parent_directories(id))
|
||||
local f = assert(io.open(id, "w"))
|
||||
gfs.make_parent_directories(id)
|
||||
local f = io.open(id, "w")
|
||||
if not f then
|
||||
gdebug.print_warning("Failed to write the history to "..id)
|
||||
return
|
||||
end
|
||||
for i = 1, math.min(#data.history[id].table, data.history[id].max) do
|
||||
f:write(data.history[id].table[i] .. "\n")
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue