src/stdlib/console/errors.panack
Green: covered; red: known zero; amber: unavailable. Blank lines are outside the executable-start-line denominator.
1 pub import stdlib/host::{HostError} 2 pub enum ConsoleOperation { Read(Nat), Write, WriteLine, WriteError, WriteErrorLine } 3 pub enum ConsoleErrorKind { 4 InvalidReadLimit, OutputTooLarge, ReadBusy, IOFailure, ResourceLimit, UnsupportedHost, OtherFailure 5 } 6 pub record ConsoleError { operation: ConsoleOperation, kind: ConsoleErrorKind, native: HostError } 7 8 impl ConsoleError { 9 pub pure render(): Str { 10 action = match self.operation { 11 Read(limit) => "read standard input (requested limit: ${limit} bytes)", 12 Write() => "write standard output", WriteLine() => "write a line to standard output", 13 WriteError() => "write standard error", WriteErrorLine() => "write a line to standard error" 14 } 15 reason = match self.kind { 16 InvalidReadLimit() => "the read limit must be from 1 through 65536 bytes. Choose a limit within that range", 17 OutputTooLarge() => "the message exceeds 16384 UTF-8 bytes before the optional newline. Write smaller chunks", 18 ReadBusy() => "another read of standard input is still outstanding. Wait for that read to finish before starting another", 19 IOFailure() => "the host could not complete the I/O operation. Check that the stream is open and available", 20 ResourceLimit() => "a console worker could not be started or all available workers are occupied. Retry after outstanding operations finish", 21 UnsupportedHost() => "this host does not support the console operation", 22 OtherFailure() => "the host returned an unrecognised failure. The native field preserves its details" 23 } 24 number = self.native.native_code 25 detail = if number == 0 { "" } else { " Host error number: ${number}." } 26 "Cannot ${action}: ${reason}.${detail}" 27 } 28 } 29 30 pub pure convert[T](result: Result[T,HostError], operation: ConsoleOperation): Result[T,ConsoleError] { 31 match result { 32 Ok(value) => Ok(value), 33 Error(problem) => { 34 kind = if problem.code == "out_of_range" { 35 match operation { 36 Read(_) => InvalidReadLimit(), Write() => OutputTooLarge(), 37 WriteLine() => OutputTooLarge(), WriteError() => OutputTooLarge(), WriteErrorLine() => OutputTooLarge() 38 } 39 } else if problem.code == "busy" { ReadBusy() } 40 else if problem.code == "io_error" { IOFailure() } 41 else if problem.code == "resource_limit" { ResourceLimit() } 42 else if problem.code == "unsupported_host" { UnsupportedHost() } 43 else { OtherFailure() } 44 Error(ConsoleError(operation, kind, problem)) 45 } 46 } 47 } 48
Functions
[
{
"id": "declaration/4",
"name": "$owned$ConsoleError$render",
"line": 9,
"state": "covered",
"entries": "7"
},
{
"id": "declaration/5",
"name": "convert",
"line": 30,
"state": "covered",
"entries": "63"
}
]Source branch outcomes
[
{
"id": "declaration/4/statement/0/value/arm/0",
"outcome": "Read",
"line": 11,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/4/statement/0/value/arm/1",
"outcome": "Write",
"line": 12,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/0/value/arm/2",
"outcome": "WriteLine",
"line": 12,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/0/value/arm/3",
"outcome": "WriteError",
"line": 13,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/0/value/arm/4",
"outcome": "WriteErrorLine",
"line": 13,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/0",
"outcome": "InvalidReadLimit",
"line": 16,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/1",
"outcome": "OutputTooLarge",
"line": 17,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/2",
"outcome": "ReadBusy",
"line": 18,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/3",
"outcome": "IOFailure",
"line": 19,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/4",
"outcome": "ResourceLimit",
"line": 20,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/5",
"outcome": "UnsupportedHost",
"line": 21,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/6",
"outcome": "OtherFailure",
"line": 22,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/3/value/decision/true",
"outcome": "true",
"line": 25,
"state": "covered",
"hits": "5"
},
{
"id": "declaration/4/statement/3/value/decision/false",
"outcome": "false",
"line": 25,
"state": "covered",
"hits": "2"
},
{
"id": "declaration/5/tail/arm/0",
"outcome": "Ok",
"line": 32,
"state": "covered",
"hits": "41"
},
{
"id": "declaration/5/tail/arm/1",
"outcome": "Error",
"line": 33,
"state": "covered",
"hits": "22"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/decision/true",
"outcome": "true",
"line": 34,
"state": "covered",
"hits": "17"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/decision/false",
"outcome": "false",
"line": 34,
"state": "covered",
"hits": "5"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/true/tail/arm/0",
"outcome": "Read",
"line": 36,
"state": "covered",
"hits": "5"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/true/tail/arm/1",
"outcome": "Write",
"line": 36,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/true/tail/arm/2",
"outcome": "WriteLine",
"line": 37,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/true/tail/arm/3",
"outcome": "WriteError",
"line": 37,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/true/tail/arm/4",
"outcome": "WriteErrorLine",
"line": 37,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/decision/true",
"outcome": "true",
"line": 39,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/decision/false",
"outcome": "false",
"line": 39,
"state": "covered",
"hits": "4"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 40,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 40,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 41,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 41,
"state": "covered",
"hits": "2"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 42,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 42,
"state": "covered",
"hits": "1"
}
]Reviewed declaration exclusions
[
{
"id": "declaration/0",
"reason": "import",
"line": 1
},
{
"id": "declaration/1",
"reason": "enum-declaration",
"line": 2
},
{
"id": "declaration/2",
"reason": "enum-declaration",
"line": 3
},
{
"id": "declaration/3",
"reason": "record-declaration",
"line": 6
}
]