about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2025-08-17 16:10:59 +0100
committerArun Isaac2025-08-17 16:10:59 +0100
commitd19c7d672d13a97507066cec5604ab94f9ba3018 (patch)
tree27adaafafc6cec521a1c5d8e2b5f9381ff092891
parent8044c5646e7b426a2b6362efdb9d33efd5fb5ff7 (diff)
downloadravanan-d19c7d672d13a97507066cec5604ab94f9ba3018.tar.gz
ravanan-d19c7d672d13a97507066cec5604ab94f9ba3018.tar.lz
ravanan-d19c7d672d13a97507066cec5604ab94f9ba3018.zip
work/command-line-tool: Raise exception on unsupported URI schemes.
location->path now raises an &unsupported-uri-scheme condition on
unsupported URI schemes.
-rw-r--r--ravanan/work/command-line-tool.scm24
1 files changed, 19 insertions, 5 deletions
diff --git a/ravanan/work/command-line-tool.scm b/ravanan/work/command-line-tool.scm
index 3c9934f..38673a0 100644
--- a/ravanan/work/command-line-tool.scm
+++ b/ravanan/work/command-line-tool.scm
@@ -17,6 +17,7 @@
 ;;; along with ravanan.  If not, see <https://www.gnu.org/licenses/>.
 
 (define-module (ravanan work command-line-tool)
+  #:use-module (rnrs conditions)
   #:use-module (rnrs exceptions)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9 gnu)
@@ -33,7 +34,11 @@
   #:use-module (ravanan work ui)
   #:use-module (ravanan work utils)
   #:use-module (ravanan work vectors)
-  #:export (value->string
+  #:export (unsupported-uri-scheme
+            unsupported-uri-scheme?
+            unsupported-uri-scheme-scheme
+
+            value->string
             call-with-current-directory
             object-type
             match-type
@@ -58,6 +63,10 @@
             command-line-binding->args
             build-command))
 
+(define-condition-type &unsupported-uri-scheme &serious
+  unsupported-uri-scheme unsupported-uri-scheme?
+  (scheme unsupported-uri-scheme-scheme))
+
 (define (value->string x)
   "Convert value @var{x} to a string."
   (cond
@@ -229,11 +238,16 @@ status in @var{success-codes} as success. Error out otherwise."
   (string-append "sha1$" (sha1-hash file)))
 
 (define (location->path location)
-  "Convert file @var{location} URI to path. Tolerate invalid locations that are
-actually paths."
+  "Convert file @var{location} @code{file://} URI to path. Tolerate invalid
+locations that are actually paths. Raise an @code{&unsupported-uri-scheme}
+condition on unsupported URI schemes."
   (cond
-   ;; If location is an URI, parse the URI and return the path part.
-   ((string->uri location) => uri-path)
+   ;; If location is a file:// URI, parse the URI and return the path part.
+   ((string->uri location)
+    => (lambda (uri)
+         (if (eq? (uri-scheme uri) 'file)
+             (uri-path uri)
+             (raise-exception (unsupported-uri-scheme (uri-scheme uri))))))
    ;; location is actually a path; return as is.
    (else location)))