From 12e857ab9562320806fd0f7fe5fa19a1a395556a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 10 May 2016 14:05:16 -0300 Subject: [PATCH] Improve readability of the error message --- validate.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/validate.el b/validate.el index 7dfe45b01..2d66a2785 100644 --- a/validate.el +++ b/validate.el @@ -64,6 +64,9 @@ "wrong number of elements" (seq-find #'identity (seq-mapn #'validate--check values schemas)))) +(defun validate--indent-by-2 (x) + (replace-regexp-in-string "^" " " x)) + (defun validate--check (value schema) "Return nil if VALUE matches SCHEMA. If they don't match, return an explanation." @@ -127,8 +130,8 @@ If they don't match, return an explanation." (error "`choice' needs at least one argument") (let ((gather (mapcar (lambda (x) (validate--check value x)) args))) (when (seq-every-p #'identity gather) - (concat "all of the options failed\n " - (mapconcat #'identity gather "\n ")))))) + (concat "all of the options failed\n" + (mapconcat #'validate--indent-by-2 gather "\n")))))) ;; TODO: `restricted-sexp' (set (or (wtype 'list) (let ((failed (list t))) @@ -145,7 +148,10 @@ If they don't match, return an explanation." (let ((print-length 4) (print-level 2)) (format "Looking for `%S' in `%S' failed because:\n%s" - schema value r)))))) + schema value + (if (string-match "\\`Looking" r) + r + (validate--indent-by-2 r)))))))) ;;; Exposed API -- 2.39.2