File: string.ha

package info (click to toggle)
hare 0.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,756 kB
  • sloc: asm: 1,180; sh: 119; makefile: 116; lisp: 99
file content (45 lines) | stat: -rw-r--r-- 1,813 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-License-Identifier: MPL-2.0
// (c) Hare authors <https://harelang.org>

// Converts an [[error]] into a human-friendly string representation.
//
// Note that this strerror implementation lacks any context-specific information
// about the error types supported. For example, [[exists]] is stringified as "An
// attempt was made to create a resource which already exists", but if source of
// the error is, say, creating a file, it would likely be more appropriate to
// use the term "file" rather than "resource". For this reason, it is preferred
// that modules which return an error type from this module provide their own
// strerror function which provides more context-appropriate error messages for
// each of those types.
export fn strerror(err: error) const str = match (err) {
case busy =>
	yield "The requested resource is not available";
case exists =>
	yield "An attempt was made to create a resource which already exists";
case invalid =>
	yield "A function was called with an invalid combination of arguments";
case noaccess =>
	yield "The user does not have permission to use this resource";
case noentry =>
	yield "An entry was requested which does not exist";
case overflow =>
	yield "The requested operation caused a numeric overflow condition";
case unsupported =>
	yield "The requested operation is not supported";
case timeout =>
	yield "The requested operation timed out";
case cancelled =>
	yield "The requested operation was cancelled";
case refused =>
	yield "A connection attempt was refused";
case nomem =>
	yield "Unable to allocate sufficient memory for the requested operation";
case interrupted =>
	yield "Operation interrupted";
case again =>
	yield "Try again";
case netunreachable =>
	yield "Network unreachable";
case let op: opaque_ =>
	yield op.strerror(&op.data);
};