std/resource/error
std/resource/src/error.trb
ResourceError: why reading a shipped Resource failed (docs/design/RESOURCES.md section 4). Every case names the
resource by its stable name and none carries a directory of the machine, so the message reads the same wherever the
program runs.
type ResourceError
type ResourceError with Show, Equals, Error
Why reading a Resource failed: it is not beside the program, it cannot be read, it is not text, or the program
cannot tell where it is.
Examples
use Resource from "std/resource"
fn show(sheet: Resource): Task<Void> {
match sheet.text().await() {
Ok(text) => print text
Fail(.NotShipped(name)) => print "{name} did not come with this build"
Fail(problem) => printError "{problem}"
}
}
Related
Resource-bytes()andtext()fail with this.
case NotShipped
case NotShipped(name: String)
The file is not in the resource directory of the program: it was not shipped, or the binary was moved without it.
case Unreadable
case Unreadable(name: String, reason: String)
The file is there and could not be read, in the operating system's own words.
case NotUtf8
case NotUtf8(name: String, offset: Int)
text() of a file whose bytes are not UTF-8. offset counts bytes from the start of the file.
case Unlocated
case Unlocated(name: String, reason: String)
The program cannot find its own location, so there is no resource directory to look in.
fn show
fn show(): String
One sentence that names the resource and what went wrong: the resource acme/game/hero.png was not shipped.