From b46a00f1856947d66c8f74b9f24f7574133a1663 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sat, 6 Aug 2022 09:09:42 -0500 Subject: [fix] saving local state after command finishes --- lib/state.lisp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'lib/state.lisp') diff --git a/lib/state.lisp b/lib/state.lisp index 49cd5d8..e690f37 100644 --- a/lib/state.lisp +++ b/lib/state.lisp @@ -169,19 +169,23 @@ sets the api's *host* variable. If BODY produces no errors, the " `(let* ((*config* (ensure-config)) (*cache* (read-cache-file)) (*drafts* (read-drafts-file)) - (api:*host* (config-host *config*))) - (handler-case - (progn - (assert api:*host* () "ol must be configured with a server host.") - (set-term-width) - ,@body - ;; only if there is no error do we save the local state. - (write-drafts-to-disk) - (write-cache-to-disk) - (write-config-to-disk)) - (dexador.error:http-request-failed (e) - (format *error-output* "Operation failed. The server at ~a returned with ~a~%" - api:*host* - (dexador.error:response-status e))) - (error (e) - (format *error-output* "~a~%" e))))) + (api:*host* (config-host *config*)) + (errorsp nil)) + (unwind-protect + (handler-case + (progn + (assert api:*host* () "ol must be configured with a server host.") + (set-term-width) + ,@body) + (dexador.error:http-request-failed (e) + (setf errorsp t) + (format *error-output* "Operation failed. The server at ~a returned with ~a~%" + api:*host* + (dexador.error:response-status e))) + (error (e) + (setf errorsp t) + (format *error-output* "Unknown Error: ~a~%" e))) + (unless errorsp + (write-drafts-to-disk) + (write-cache-to-disk) + (write-config-to-disk))))) -- cgit v1.2.3