summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-07-05 10:37:16 +0530
committerArun Isaac2022-07-05 10:37:16 +0530
commit702c61f21a42d1f67e576f4100f61ca5f597e4df (patch)
tree4b071b39b7ee78bed447956fcfb4708328b90e4a
parentda1a10cc577699e69b6de99c7373b59d9ba726d0 (diff)
downloadtissue-702c61f21a42d1f67e576f4100f61ca5f597e4df.tar.gz
tissue-702c61f21a42d1f67e576f4100f61ca5f597e4df.tar.lz
tissue-702c61f21a42d1f67e576f4100f61ca5f597e4df.zip
bin: Guard main function against all git errors.
* bin/tissue (main): Guard against git errors printing the error message instead of a backtrace.
-rwxr-xr-xbin/tissue85
1 files changed, 45 insertions, 40 deletions
diff --git a/bin/tissue b/bin/tissue
index 946a240..d7736c2 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -463,45 +463,50 @@ Pull latest from upstream repositories.
(assq-ref parameters 'upstream-repository)))))
(assq-ref args 'hosts)))))))
-(define main
- (match-lambda*
- ((_ (or "-h" "--help"))
- (print-usage))
- ((_ "pull" args ...)
- (apply tissue-pull args))
- ((_ "run-web" args ...)
- (apply tissue-run-web args))
- ((_ command args ...)
- (call-with-current-directory (git-top-level)
- (lambda ()
- (let ((config (load-config)))
- (parameterize ((%aliases (tissue-configuration-aliases config)))
- ;; Create hidden tissue directory unless it exists.
- (unless (file-exists? %state-directory)
- (mkdir %state-directory))
- ;; Ensure index exists, rebuilding it if it is stale.
- (let ((current-head
- (oid->string (reference-name->oid (current-git-repository) "HEAD"))))
- (unless (and (file-exists? db-path)
- (string=? (call-with-database db-path
- (cut Database-get-metadata <> "commit"))
- current-head))
- (index %xapian-index)))
- ;; Handle sub-command.
- (apply (match command
- ("search" tissue-search)
- ("show" tissue-show)
- ("repl" tissue-repl)
- ("web" tissue-web)
- ("index" tissue-index)
- (invalid-command
- (format (current-error-port) "Invalid command `~a'~%~%"
- invalid-command)
- (print-usage)
- (exit #f)))
- args))))))
- ;; tissue is an alias for `tissue search'
- ((_)
- (main "tissue" "search"))))
+(define (main . args)
+ (guard (c ((condition-git-error c)
+ => (lambda (git-error)
+ (display (git-error-message git-error) (current-error-port))
+ (newline (current-error-port))
+ (exit #f))))
+ (match args
+ ((_ (or "-h" "--help"))
+ (print-usage))
+ ((_ "pull" args ...)
+ (apply tissue-pull args))
+ ((_ "run-web" args ...)
+ (apply tissue-run-web args))
+ ((_ command args ...)
+ (call-with-current-directory (git-top-level)
+ (lambda ()
+ (let ((config (load-config)))
+ (parameterize ((%aliases (tissue-configuration-aliases config)))
+ ;; Create hidden tissue directory unless it exists.
+ (unless (file-exists? %state-directory)
+ (mkdir %state-directory))
+ ;; Ensure index exists, rebuilding it if it is stale.
+ (let ((current-head
+ (oid->string (reference-name->oid (current-git-repository) "HEAD"))))
+ (unless (and (file-exists? db-path)
+ (string=? (call-with-database db-path
+ (cut Database-get-metadata <> "commit"))
+ current-head))
+ (index %xapian-index)))
+ ;; Handle sub-command.
+ (apply (match command
+ ("search" tissue-search)
+ ("show" tissue-show)
+ ("repl" tissue-repl)
+ ("web" tissue-web)
+ ("index" tissue-index)
+ (invalid-command
+ (format (current-error-port) "Invalid command `~a'~%~%"
+ invalid-command)
+ (print-usage)
+ (exit #f)))
+ args))))))
+ ;; tissue is an alias for `tissue search'
+ ((_)
+ (main "tissue" "search")))))
(apply main (command-line))