hare

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

error.ha (1121B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use encoding::utf8;
      5 use fmt;
      6 use fs;
      7 use io;
      8 
      9 // All possible errors returned from this module.
     10 export type error = !(
     11 	invalid
     12 	| invalidtzif
     13 	| tzdberror
     14 	| discontinuity
     15 	| analytical
     16 );
     17 
     18 // Converts an [[error]] into a human-friendly string. The result may be
     19 // statically allocated.
     20 export fn strerror(err: error) const str = {
     21 	match (err) {
     22 	case invalid =>
     23 		return "Invalid moment";
     24 	case invalidtzif =>
     25 		return "Invalid TZif data";
     26 	case let err: tzdberror =>
     27 		static let buf: [1024]u8 = [0...];
     28 		match (err) {
     29 		case let err: fs::error =>
     30 			return fmt::bsprintf(buf,
     31 				"Timezone database error: {}",
     32 				fs::strerror(err),
     33 			);
     34 		case let err: io::error =>
     35 			return fmt::bsprintf(buf,
     36 				"Timezone database error: {}",
     37 				io::strerror(err),
     38 			);
     39 		case invalidtzif =>
     40 			return "Timezone database error: Invalid TZif data";
     41 		};
     42 	case discontinuity =>
     43 		return "A timescale discontinuity caused a misconversion";
     44 	case analytical =>
     45 		return "The analyical result of a conversion at a timescale discontinuity";
     46 	};
     47 };