Skip to content

Commit 2a0bbe7

Browse files
committed
cli: don't fail if history can't be read or written
Instead, print a warning (unless in quiet mode).
1 parent 79f9730 commit 2a0bbe7

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drgn/internal/cli.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,19 @@ def main() -> None:
151151
histfile = os.path.expanduser("~/.drgn_history")
152152
try:
153153
readline.read_history_file(histfile)
154-
except FileNotFoundError:
155-
pass
156-
readline.parse_and_bind("tab: complete")
157-
readline.set_history_length(1000)
158-
atexit.register(readline.write_history_file, histfile)
154+
except OSError as e:
155+
if not isinstance(e, FileNotFoundError) and not args.quiet:
156+
print('could not read history:', str(e), file=sys.stderr)
157+
def write_history_file():
158+
try:
159+
readline.write_history_file(histfile)
160+
except OSError as e:
161+
if not args.quiet:
162+
print('could not write history:', str(e), file=sys.stderr)
163+
atexit.register(write_history_file)
159164

165+
readline.set_history_length(1000)
166+
readline.parse_and_bind("tab: complete")
160167
readline.set_completer(Completer(init_globals).complete)
161168
atexit.register(lambda: readline.set_completer(None))
162169

0 commit comments

Comments
 (0)