diff options
author | Colin Okay <colin@cicadas.surf> | 2022-08-06 09:09:42 -0500 |
---|---|---|
committer | Colin Okay <colin@cicadas.surf> | 2022-08-06 09:09:42 -0500 |
commit | b46a00f1856947d66c8f74b9f24f7574133a1663 (patch) | |
tree | ee1bdf510b7bbeae9270702f7fd75f2d093b8782 /lib/state.lisp | |
parent | 575695b5f1f204aa670b996e791822f36f47ee1d (diff) |
[fix] saving local state after command finishes
Diffstat (limited to 'lib/state.lisp')
-rw-r--r-- | lib/state.lisp | 36 |
1 files changed, 20 insertions, 16 deletions
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))))) |