hare

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

string.ha (1781B)


      1 // License: MPL-2.0
      2 // (c) 2021 Drew DeVault <sir@cmpwn.com>
      3 // (c) 2021 Eyal Sawady <ecs@d2evs.net>
      4 
      5 // Converts an [[error]] into a human-friendly string representation.
      6 //
      7 // Note that this strerror implementation lacks any context-specific information
      8 // about the error types supported. For example, [[exists]] is stringified as "An
      9 // attempt was made to create a resource which already exists", but if source of
     10 // the error is, say, creating a file, it would likely be more appropriate to
     11 // use the term "file" rather than "resource". For this reason, it is preferred
     12 // that modules which return an error type from this module provide their own
     13 // strerror function which provides more context-appropriate error messages for
     14 // each of those types.
     15 export fn strerror(err: error) const str = match (err) {
     16 case busy =>
     17 	yield "The requested resource is not available";
     18 case exists =>
     19 	yield "An attempt was made to create a resource which already exists";
     20 case invalid =>
     21 	yield "A function was called with an invalid combination of arguments";
     22 case noaccess =>
     23 	yield "The user does not have permission to use this resource";
     24 case noentry =>
     25 	yield "An entry was requested which does not exist";
     26 case overflow =>
     27 	yield "The requested operation caused a numeric overflow condition";
     28 case unsupported =>
     29 	yield "The requested operation is not supported";
     30 case timeout =>
     31 	yield "The requested operation timed out";
     32 case cancelled =>
     33 	yield "The requested operation was cancelled";
     34 case refused =>
     35 	yield "A connection attempt was refused";
     36 case nomem =>
     37 	yield "Unable to allocate sufficient memory for the requested operation";
     38 case interrupted =>
     39 	yield "Operation interrupted";
     40 case again =>
     41 	yield "Try again";
     42 case let op: opaque =>
     43 	yield op.strerror(&op.data);
     44 };