From d4667f94fbd2927e1c76a06567a92dedf1213e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 17 Mar 2022 22:15:59 +0100 Subject: Remove assert. Barely used, and almost always was better server by a propper error call. --- module/calp/html/view/calendar/shared.scm | 6 ++++-- module/hnh/util/exceptions.scm | 16 +--------------- module/vcomponent/formats/vdir/parse.scm | 17 +++++++++-------- module/vcomponent/formats/vdir/save-delete.scm | 13 ++++++++++--- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/module/calp/html/view/calendar/shared.scm b/module/calp/html/view/calendar/shared.scm index 3e6ff105..e333dc4a 100644 --- a/module/calp/html/view/calendar/shared.scm +++ b/module/calp/html/view/calendar/shared.scm @@ -1,6 +1,5 @@ (define-module (calp html view calendar shared) :use-module (hnh util) - :use-module ((hnh util exceptions) :select (assert)) :use-module (srfi srfi-1) :use-module (vcomponent) :use-module ((vcomponent datetime) @@ -32,7 +31,10 @@ ;; only find events which also overlaps the ;; smaller event. - (assert event-length-key) + (unless event-length-key + (scm-error 'wrong-type-arg "fix-event-widths!" + "event-length-key is required" + #f #f)) ;; @var{x} is how for left in the container we are. (let inner ((x 0) diff --git a/module/hnh/util/exceptions.scm b/module/hnh/util/exceptions.scm index bcfd506d..eed310bb 100644 --- a/module/hnh/util/exceptions.scm +++ b/module/hnh/util/exceptions.scm @@ -6,7 +6,7 @@ #:use-module ((system vm frame) :select (frame-bindings binding-ref)) - #:export (assert)) + ) (define-public warning-handler @@ -31,20 +31,6 @@ (raise 2) ) -(define (prettify-tree tree) - (cond [(pair? tree) (cons (prettify-tree (car tree)) - (prettify-tree (cdr tree)))] - [(and (procedure? tree) (procedure-name tree)) - => identity] - [else tree])) - - -(define-macro (assert form) - `(unless ,form - (throw 'assertion-error "Assertion failed. ~a expected, ~a got" - (quote ,form) - ((@@ (calp util exceptions) prettify-tree) (list ,form))))) - (define-public (filter-stack pred? stk) (concatenate diff --git a/module/vcomponent/formats/vdir/parse.scm b/module/vcomponent/formats/vdir/parse.scm index c4a48889..272674ed 100644 --- a/module/vcomponent/formats/vdir/parse.scm +++ b/module/vcomponent/formats/vdir/parse.scm @@ -38,12 +38,16 @@ (reduce (lambda (item calendar) - (define-values (events other) (partition (lambda (e) (eq? 'VEVENT (type e))) - (children item))) + (define-values (events other) + (partition (lambda (e) (eq? 'VEVENT (type e))) + (children item))) - ;; (assert (eq? 'VCALENDAR (type calendar))) - (assert (eq? 'VCALENDAR (type item))) + (unless (eq? 'VCALENDAR (type item)) + (scm-error 'misc-error "parse-vdir" + "Unexepected top level component. Expected VCALENDAR, got ~a. In file ~s" + (list (type item) (prop item '-X-HNH-FILENAME)) + #f)) (for child in (children item) (set! (prop child '-X-HNH-FILENAME) @@ -60,10 +64,7 @@ (case (length events) [(0) (warning "No events in component~%~a" (prop item '-X-HNH-FILENAME))] - [(1) - (let ((child (car events))) - (assert (memv (type child) '(VTIMEZONE VEVENT))) - (add-child! calendar child))] + [(1) (add-child! calendar (car events))] ;; two or more [else diff --git a/module/vcomponent/formats/vdir/save-delete.scm b/module/vcomponent/formats/vdir/save-delete.scm index 7de9379b..8fdc615e 100644 --- a/module/vcomponent/formats/vdir/save-delete.scm +++ b/module/vcomponent/formats/vdir/save-delete.scm @@ -13,7 +13,6 @@ :use-module (hnh util) :use-module (hnh util uuid) :use-module ((hnh util path) :select (path-append)) - :use-module ((hnh util exceptions) :select (assert)) :use-module (vcomponent formats ical output) :use-module (vcomponent) :use-module ((hnh util io) :select (with-atomic-output-to-file)) @@ -23,7 +22,11 @@ (define-public (save-event event) (define calendar (parent event)) - (assert (eq? 'vdir (prop calendar '-X-HNH-SOURCETYPE))) + (unless (eq? 'vdir (prop calendar '-X-HNH-SOURCETYPE)) + (scm-error 'wrong-type-arg "save-event" + "Can only save events belonging to vdir calendars. Calendar is of type ~s" + (list (prop calendar '-X-HNH-SOURCETYPE)) + #f)) (let* ((uid (or (prop event 'UID) (uuid)))) (set! (prop event 'UID) uid @@ -38,5 +41,9 @@ (define-public (remove-event event) (define calendar (parent event)) - (assert (eq? 'vdir (prop calendar '-X-HNH-SOURCETYPE))) + (unless (eq? 'vdir (prop calendar '-X-HNH-SOURCETYPE)) + (scm-error 'wrong-type-arg "remove-event" + "Can only remove events belonging to vdir calendars. Calendar is of type ~s" + (list (prop calendar '-X-HNH-SOURCETYPE)) + #f)) (delete-file (prop event '-X-HNH-FILENAME))) -- cgit v1.2.3