shithub: mc

Download patch

ref: c2a04cf2cb447ffb3c24d91e7978ef170460bf46
parent: fd3494af3e5209e7e74662bc4066b28f58ff49cc
author: Ori Bernstein <[email protected]>
date: Sun Jun 14 18:54:24 EDT 2015

Bio returns errors on failed opens.

    Not option, but result.

--- a/libbio/bio.myr
+++ b/libbio/bio.myr
@@ -23,9 +23,9 @@
 
 	/* creation */
 	const mkfile	: (fd : std.fd, mode : mode	-> file#)
-	const open	: (path : byte[:], mode : mode	-> std.option(file#))
-	const dial	: (srv	: byte[:], mode : mode	-> std.option(file#))
-	const create	: (path : byte[:], mode : mode, perm : int	-> std.option(file#))
+	const open	: (path : byte[:], mode : mode	-> std.result(file#, byte[:]))
+	const dial	: (srv	: byte[:], mode : mode	-> std.result(file#, byte[:]))
+	const create	: (path : byte[:], mode : mode, perm : int	-> std.result(file#, byte[:]))
 	const close	: (f : file# -> bool)
 	const free	: (f : file# -> void)
 
@@ -98,8 +98,8 @@
 /* dial the server, and open a file using the returned fd */
 const dial = {srv, mode
 	match std.dial(srv)
-	| `std.Ok sock:	-> `std.Some mkfile(sock, mode)
-	| `std.Fail _:	-> `std.None
+	| `std.Ok sock:	-> `std.Ok mkfile(sock, mode)
+	| `std.Fail m:	-> `std.Fail m
 	;;
 }
 
@@ -120,9 +120,9 @@
 
 	fd = std.openmode(path, openmode, perm castto(int64))
 	if fd < 0
-		-> `std.None
+		-> `std.Fail "could not open fd"
 	else
-		-> `std.Some mkfile(fd, mode)
+		-> `std.Ok mkfile(fd, mode)
 	;;
 }
 
--- a/libregex/redump.myr
+++ b/libregex/redump.myr
@@ -45,11 +45,11 @@
 
 	for f in files
 		match bio.open(f, bio.Rd)
-		| `std.Some fd:
+		| `std.Ok fd:
 			dump(re, fd)
 			bio.close(fd)
-		| `std.None:
-			std.fatal("failed to open {}\n", f)
+		| `std.Fail m:
+			std.fatal("failed to open {}: {}\n", f, m)
 		;;
 	;;
 }
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -198,8 +198,8 @@
 		;;
 	;;
 	match bio.open(path, bio.Rd)
-	| `std.Some fd:	f = fd
-	| `std.None:	std.fatal("could not open {}\n", path)
+	| `std.Ok fd:	f = fd
+	| `std.Fail m:	std.fatal("could not open {}: {}\n", path, m)
 	;;
 
 	lnum = 0
@@ -263,18 +263,14 @@
 	for p in incs
 		path = std.pathjoin([p, lib][:])
 		match  bio.open(path, bio.Rd)
-		| `std.Some file:
-			-> file
-		| `std.None:
-			/* nothing */
+		| `std.Ok file:	-> file
+		| `std.Fail m:	/* nothing */
 		;;
 	;;
 	path = std.pathjoin([opt_instroot, "/lib/myr", lib][:])
 	match  bio.open(path, bio.Rd)
-	| `std.Some file:
-		-> file
-	| `std.None:
-		/* nothing */
+	| `std.Ok file:	-> file
+	| `std.Fail m:	/* nothing */
 	;;
 	std.fatal("could not find library {}.\n", lib)
 }