aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-03-17 22:15:59 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-03-28 14:17:47 +0200
commitd4667f94fbd2927e1c76a06567a92dedf1213e43 (patch)
tree1db96f4ee662f2b221790318feaa48b66044aa82
parentUse catch* where appropriate (diff)
downloadcalp-d4667f94fbd2927e1c76a06567a92dedf1213e43.tar.gz
calp-d4667f94fbd2927e1c76a06567a92dedf1213e43.tar.xz
Remove assert.
Barely used, and almost always was better server by a propper error call.
-rw-r--r--module/calp/html/view/calendar/shared.scm6
-rw-r--r--module/hnh/util/exceptions.scm16
-rw-r--r--module/vcomponent/formats/vdir/parse.scm17
-rw-r--r--module/vcomponent/formats/vdir/save-delete.scm13
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)))