Fix error on binary files

Evgeny PisemskyTue Aug 27 09:20:09+0300 2024

acc27e8

Fix error on binary files

gitile/pages.scm

9999
       (a (@ (href "/" ,repository-name "/raw/" ,(or ref "-")
100100
                   "/" ,path))
101101
          (img (@ (src "/images/file-type-3.svg"))))))
102-
    ,(let ((content (utf8->string (get-file-content repo path #:ref ref))))
103-
       (if (string-suffix? ".md" path)
104-
         `(article (@ (class "formatted-file-content"))
105-
            ,(improve-content (commonmark->sxml content)))
106-
         (display-code content path)))))
102+
    ,(with-exception-handler
103+
         (lambda (exn)
104+
           `(pre "Binary data"))
105+
       (lambda ()
106+
         (let ((content (utf8->string (get-file-content repo path #:ref ref))))
107+
           (if (string-suffix? ".md" path)
108+
               `(article (@ (class "formatted-file-content"))
109+
                         ,(improve-content (commonmark->sxml content)))
110+
               (display-code content path))))
111+
       #:unwind? #t)))
107112
108113
(define* (project-files repository-name repo #:key (ref "-") (path '()))
109114
  (let* ((ref (if (equal? ref "-") #f ref))