hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

error.ha (708B)


      1 // SPDX-License-Identifier: MIT
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use encoding::utf8;
      5 use io;
      6 use os::exec;
      7 
      8 // Tagged union of possible wordexp error conditions.
      9 export type error = !(io::error | exec::error | utf8::invalid | sh_error);
     10 
     11 // An error occured during shell expansion.
     12 export type sh_error = !void;
     13 
     14 // Converts an [[error]] to a human-friendly string.
     15 export fn strerror(err: error) const str = {
     16 	match (err) {
     17 	case let err: io::error =>
     18 		return io::strerror(err);
     19 	case let err: exec::error =>
     20 		return exec::strerror(err);
     21 	case utf8::invalid =>
     22 		return "Word expansion returned invalid UTF-8 data";
     23 	case sh_error =>
     24 		return "An error occured during shell expansion";
     25 	};
     26 };