(in-package :pkgmgr-except) ;; Define an 'extended' condition that satisfies what I would personally ;; consider a minimal base condition - in other words, being able to ;; specify a generic human-readable error message aswell as specify ;; an underlying cause for the condition (in the form of another ;; condition). (define-condition extended-condition (condition) ((message :accessor extended-condition-message :initarg :message :initform nil) (cause :accessor extended-condition-cause :initarg :cause :initform nil) (kvlist :accessor extended-condition-kvlist :initarg :kvlist :initform nil)) (:report (lambda (condition stream) (format stream "~a" (extended-condition-report condition))))) (defmethod extended-condition-report (condition) (with-accessors ((message extended-condition-message) (cause extended-condition-cause) (kvlist extended-condition-kvlist)) condition (format nil "Condition of type ~a: ~a (cause: ~a)" (class-name (class-of condition)) (if (and (typep condition 'extended-condition) (extended-condition-extended-message condition)) (extended-condition-extended-message condition) (format nil "~a, ~a" message kvlist)) cause))) (define-condition extended-error (extended-condition error) ()) ;; Method to be overrided for classes that want to include more information ;; than just the message given using :message. Implementors must also ;; print :message if is to be shown, as this message is printed instead ;; of the message. (defmethod extended-condition-extended-message ((c condition)) nil)