hare

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

string.ha (1760B)


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