From 06f1c5825254a6806ac34fa8b2797fceaca6c7c9 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 18 Nov 2023 09:05:46 -0800 Subject: Fix: handle dns errors --- fussy.lisp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'fussy.lisp') diff --git a/fussy.lisp b/fussy.lisp index 7b6d706..2df651e 100644 --- a/fussy.lisp +++ b/fussy.lisp @@ -4,6 +4,9 @@ (defvar +default-emacs-package-archive+ "https://melpa.org/packages/archive-contents") +(defparameter +retry-wait+ 60 + "Nubmer of seconds to wait between http request retries.") + (defun emacs-reader-readtable () "Return a readtable that will read the emacs package archive contents." @@ -15,15 +18,25 @@ contents." (set-macro-character #\] (get-macro-character #\) nil)) *readtable*))) -(defun fetch-emacs-archive (&optional (archive +default-emacs-package-archive+)) +(defun fetch-emacs-archive + (&optional + (archive +default-emacs-package-archive+) + (retries 10)) "Fetch the package archive from ARCHIVE, a url, and read it in using the emacs' reader readtable." ;; TODO: HANDLE HTTP ERRORS, HANDLE TIMEOUT, HANDLE READ ERRORS - (multiple-value-bind (stream status) (dexador:get archive :want-stream t) - (when (= 200 status) - (let* ((*package* (find-package :fussy)) - (*readtable* (emacs-reader-readtable))) - (read stream))))) + (when (plusp retries) + (handler-case + (multiple-value-bind (stream status) (dexador:get archive :want-stream t) + (when (= 200 status) + (let* ((*package* (find-package :fussy)) + (*readtable* (emacs-reader-readtable))) + (read stream)))) + (usocket:ns-host-not-found-error () + (fussy-log "Host Not Found: ~a~%Retrying in ~a seconds...~%" + archive +retry-wait+) + (sleep +retry-wait+) + (fetch-emacs-archive archive (1- retries)))))) (defclass/std theme-pkg (db:store-object) ((name -- cgit v1.2.3