src/stdlib/compression/gzip/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 GzipOperation { CreateDecoder(Nat), DecodeChunk(Nat, Bool), Close } 3 pub enum GzipErrorKind { 4 InvalidDecoder, ChunkTooLarge, UnsupportedOutputLimit, OutputLimitExceeded, 5 DecoderStopped, DecodeFailed, IncompleteInput, DecoderUnavailable, 6 InvalidArgument, ResourceLimit, UnsupportedHost, OtherFailure 7 } 8 pub record GzipError { operation: GzipOperation, kind: GzipErrorKind, native: HostError } 9 10 impl GzipError { 11 pub pure render(): Str { 12 action = match self.operation { 13 CreateDecoder(limit) => "create a gzip decoder with an output limit of ${limit} bytes", 14 DecodeChunk(size, finish) => { 15 finality = if finish { "marked as final input" } else { "with more input allowed" } 16 "decode a gzip chunk of ${size} bytes (${finality})" 17 }, 18 Close() => "close a gzip decoder" 19 } 20 reason = match self.kind { 21 InvalidDecoder() => "the decoder is not usable in this invocation. Use a decoder created here that has not been closed", 22 ChunkTooLarge() => "a decoding step accepts at most 65536 input bytes. Split the input into smaller chunks and resubmit each unconsumed suffix", 23 UnsupportedOutputLimit() => "the output limit must be at most 268435456 bytes (256 MiB). Choose a supported limit; zero permits no decompressed output", 24 OutputLimitExceeded() => "decompressed data exceeded the output budget selected when this decoder was created. Close the decoder; to allow more output, create a new decoder with a supported larger budget and supply the compressed input again", 25 DecoderStopped() => "this decoder no longer accepts input. Close it and create a new decoder if another stream must be decoded", 26 DecodeFailed() => "zlib could not decode this input as gzip. The native API has not supplied a more specific cause. Check that the input is complete gzip data; close this decoder before trying again with a new decoder", 27 IncompleteInput() => "the input was marked as final before a complete gzip member was available. Close this decoder and start again with the complete compressed input; mark only the final input as final", 28 DecoderUnavailable() => "zlib could not initialise or reset the decoder. The native API has not supplied a more specific cause; if a decoder already exists, close it before creating another", 29 InvalidArgument() => "the host rejected an argument. Check the operation’s documented requirements", 30 ResourceLimit() => "the host could not allocate another decoder slot. An invocation can create at most 64 decoders, including decoders already closed; closing a decoder does not reset that quota", 31 UnsupportedHost() => "this host does not support gzip decoding", 32 OtherFailure() => "the host returned an unrecognised failure. The native field preserves its details" 33 } 34 number = self.native.native_code 35 detail = if number == 0 { "" } else { " Host error number: ${number}." } 36 "Cannot ${action}: ${reason}.${detail}" 37 } 38 } 39 40 pub pure convert[T](result: Result[T,HostError], operation: GzipOperation): Result[T,GzipError] { 41 match result { 42 Ok(value) => Ok(value), 43 Error(problem) => { 44 kind = if problem.code == "invalid_handle" { InvalidDecoder() } 45 else if problem.code == "invalid_argument" { 46 match operation { 47 CreateDecoder(limit) => if limit > 268435456 { UnsupportedOutputLimit() } else { InvalidArgument() }, 48 DecodeChunk(size, _) => if size > 65536 { ChunkTooLarge() } else { InvalidArgument() }, 49 Close() => InvalidArgument() 50 } 51 } else if problem.code == "output_limit" { 52 match operation { 53 CreateDecoder(_) => UnsupportedOutputLimit(), DecodeChunk(ignored_size, ignored_final) => OutputLimitExceeded(), 54 Close() => OtherFailure() 55 } 56 } else if problem.code == "decoder_finished" { DecoderStopped() } 57 else if problem.code == "invalid_gzip" { DecodeFailed() } 58 else if problem.code == "truncated_gzip" { IncompleteInput() } 59 else if problem.code == "decoder_unavailable" { DecoderUnavailable() } 60 else if problem.code == "resource_limit" { ResourceLimit() } 61 else if problem.code == "unsupported" || problem.code == "unsupported_host" { UnsupportedHost() } 62 else { OtherFailure() } 63 Error(GzipError(operation, kind, problem)) 64 } 65 } 66 } 67
Functions
[
{
"id": "declaration/4",
"name": "$owned$GzipError$render",
"line": 11,
"state": "covered",
"entries": "20"
},
{
"id": "declaration/5",
"name": "convert",
"line": 40,
"state": "covered",
"entries": "322"
}
]Source branch outcomes
[
{
"id": "declaration/4/statement/0/value/arm/0",
"outcome": "CreateDecoder",
"line": 13,
"state": "covered",
"hits": "5"
},
{
"id": "declaration/4/statement/0/value/arm/1",
"outcome": "DecodeChunk",
"line": 14,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/4/statement/0/value/arm/1/body/block/statement/0/value/decision/true",
"outcome": "true",
"line": 15,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/0/value/arm/1/body/block/statement/0/value/decision/false",
"outcome": "false",
"line": 15,
"state": "covered",
"hits": "2"
},
{
"id": "declaration/4/statement/0/value/arm/2",
"outcome": "Close",
"line": 18,
"state": "covered",
"hits": "12"
},
{
"id": "declaration/4/statement/1/value/arm/0",
"outcome": "InvalidDecoder",
"line": 21,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/1",
"outcome": "ChunkTooLarge",
"line": 22,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/2",
"outcome": "UnsupportedOutputLimit",
"line": 23,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/4/statement/1/value/arm/3",
"outcome": "OutputLimitExceeded",
"line": 24,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/4",
"outcome": "DecoderStopped",
"line": 25,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/5",
"outcome": "DecodeFailed",
"line": 26,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/6",
"outcome": "IncompleteInput",
"line": 27,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/7",
"outcome": "DecoderUnavailable",
"line": 28,
"state": "covered",
"hits": "2"
},
{
"id": "declaration/4/statement/1/value/arm/8",
"outcome": "InvalidArgument",
"line": 29,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/1/value/arm/9",
"outcome": "ResourceLimit",
"line": 30,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/4/statement/1/value/arm/10",
"outcome": "UnsupportedHost",
"line": 31,
"state": "covered",
"hits": "4"
},
{
"id": "declaration/4/statement/1/value/arm/11",
"outcome": "OtherFailure",
"line": 32,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/statement/3/value/decision/true",
"outcome": "true",
"line": 35,
"state": "covered",
"hits": "16"
},
{
"id": "declaration/4/statement/3/value/decision/false",
"outcome": "false",
"line": 35,
"state": "covered",
"hits": "4"
},
{
"id": "declaration/5/tail/arm/0",
"outcome": "Ok",
"line": 42,
"state": "covered",
"hits": "273"
},
{
"id": "declaration/5/tail/arm/1",
"outcome": "Error",
"line": 43,
"state": "covered",
"hits": "49"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/decision/true",
"outcome": "true",
"line": 44,
"state": "covered",
"hits": "5"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/decision/false",
"outcome": "false",
"line": 44,
"state": "covered",
"hits": "44"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/decision/true",
"outcome": "true",
"line": 45,
"state": "covered",
"hits": "9"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/decision/false",
"outcome": "false",
"line": 45,
"state": "covered",
"hits": "35"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/0",
"outcome": "CreateDecoder",
"line": 47,
"state": "covered",
"hits": "4"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/0/body/decision/true",
"outcome": "true",
"line": 47,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/0/body/decision/false",
"outcome": "false",
"line": 47,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/1",
"outcome": "DecodeChunk",
"line": 48,
"state": "covered",
"hits": "4"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/1/body/decision/true",
"outcome": "true",
"line": 48,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/1/body/decision/false",
"outcome": "false",
"line": 48,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/2",
"outcome": "Close",
"line": 49,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 51,
"state": "covered",
"hits": "11"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 51,
"state": "covered",
"hits": "24"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/true/tail/arm/0",
"outcome": "CreateDecoder",
"line": 53,
"state": "covered",
"hits": "5"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/true/tail/arm/1",
"outcome": "DecodeChunk",
"line": 53,
"state": "covered",
"hits": "5"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/true/tail/arm/2",
"outcome": "Close",
"line": 54,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 56,
"state": "covered",
"hits": "9"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 56,
"state": "covered",
"hits": "15"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 57,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 57,
"state": "covered",
"hits": "12"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 58,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 58,
"state": "covered",
"hits": "9"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 59,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 59,
"state": "covered",
"hits": "8"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 60,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 60,
"state": "covered",
"hits": "5"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 61,
"state": "covered",
"hits": "2"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 61,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/condition/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 61,
"state": "covered",
"hits": "4"
},
{
"id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/false/tail/condition/decision/skip-right",
"outcome": "skip-right",
"line": 61,
"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": 8
}
]