;; Copyright (c) 2024, SWGY, Inc. <ron@sw.gy>
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3 of the License, or (at
;; your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software Foundation, Inc.,
;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
;;
(in-package :swtx)
(define-condition bad-attribute-value-error ()
((attribute-name :initarg :attribute-name
:reader attribute-name
:documentation "Name of the attribute with a bad value.")
(details :initarg :details :initform "No additional details"
:reader details
:documentation
"Provides additional information about the nature of the problem."))
(:report (lambda (condition stream)
(format stream "Attribute value for '~A' was rejected: ~A.~&"
(attribute-name condition)
(details condition))))
(:documentation "Indicates a provided attribute value was invalid."))
(defmethod to-hash ((c bad-attribute-value-error))
"Build a hashtable representing the properties of this error"
(let ((result (make-hash-table)))
(setf (gethash "attribute-name" result) (attribute-name c))
(setf (gethash "details" result) (details c))
result))