hare

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

error.ha (1101B)


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