aboutsummaryrefslogtreecommitdiff
path: root/lib/state.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/state.lisp')
-rw-r--r--lib/state.lisp36
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)))))