All files

src/stdlib/time/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 SleepErrorKind { NegativeDuration, DurationTooLarge, TimerFailure, UnsupportedHost, OtherFailure }
    3 pub record SleepError { duration: Duration, kind: SleepErrorKind, native: HostError }
    4 impl SleepError {
    5   pub pure render(): Str {
    6     nanoseconds = self.duration.as_nanoseconds()
    7     reason = match self.kind {
    8       NegativeDuration() => "the duration is negative. Use zero or a positive duration",
    9       DurationTooLarge() => "the duration exceeds the host timer's supported range (at most 365 days). Choose a shorter duration",
   10       TimerFailure() => "the host timer could not complete the wait",
   11       UnsupportedHost() => "this host does not support waiting",
   12       OtherFailure() => "the host returned an unrecognised timer failure. The native field preserves its details"
   13     }
   14     number = self.native.native_code
   15     detail = if number == 0 { "" } else { " Host error number: ${number}." }
   16     "Cannot sleep for ${nanoseconds} nanoseconds: ${reason}.${detail}"
   17   }
   18 }
   19 pub pure convert(result: Result[Unit,HostError], duration: Duration): Result[Unit,SleepError] {
   20   match result {
   21     Ok(value) => Ok(value),
   22     Error(problem) => {
   23       kind = if problem.code == "negative_duration" { NegativeDuration() }
   24       else if problem.code == "out_of_range" { DurationTooLarge() }
   25       else if problem.code == "io_error" || problem.code == "clock_unavailable" { TimerFailure() }
   26       else if problem.code == "unsupported_host" { UnsupportedHost() }
   27       else { OtherFailure() }
   28       Error(SleepError(duration, kind, problem))
   29     }
   30   }
   31 }
   32 

Functions

[
  {
    "id": "declaration/3",
    "name": "$owned$SleepError$render",
    "line": 5,
    "state": "covered",
    "entries": "6"
  },
  {
    "id": "declaration/4",
    "name": "convert",
    "line": 19,
    "state": "covered",
    "entries": "11"
  }
]

Source branch outcomes

[
  {
    "id": "declaration/3/statement/1/value/arm/0",
    "outcome": "NegativeDuration",
    "line": 8,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/3/statement/1/value/arm/1",
    "outcome": "DurationTooLarge",
    "line": 9,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/3/statement/1/value/arm/2",
    "outcome": "TimerFailure",
    "line": 10,
    "state": "covered",
    "hits": "2"
  },
  {
    "id": "declaration/3/statement/1/value/arm/3",
    "outcome": "UnsupportedHost",
    "line": 11,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/3/statement/1/value/arm/4",
    "outcome": "OtherFailure",
    "line": 12,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/3/statement/3/value/decision/true",
    "outcome": "true",
    "line": 15,
    "state": "covered",
    "hits": "5"
  },
  {
    "id": "declaration/3/statement/3/value/decision/false",
    "outcome": "false",
    "line": 15,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/4/tail/arm/0",
    "outcome": "Ok",
    "line": 21,
    "state": "covered",
    "hits": "3"
  },
  {
    "id": "declaration/4/tail/arm/1",
    "outcome": "Error",
    "line": 22,
    "state": "covered",
    "hits": "8"
  },
  {
    "id": "declaration/4/tail/arm/1/body/block/statement/0/value/decision/true",
    "outcome": "true",
    "line": 23,
    "state": "covered",
    "hits": "2"
  },
  {
    "id": "declaration/4/tail/arm/1/body/block/statement/0/value/decision/false",
    "outcome": "false",
    "line": 23,
    "state": "covered",
    "hits": "6"
  },
  {
    "id": "declaration/4/tail/arm/1/body/block/statement/0/value/false/tail/decision/true",
    "outcome": "true",
    "line": 24,
    "state": "covered",
    "hits": "2"
  },
  {
    "id": "declaration/4/tail/arm/1/body/block/statement/0/value/false/tail/decision/false",
    "outcome": "false",
    "line": 24,
    "state": "covered",
    "hits": "4"
  },
  {
    "id": "declaration/4/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 25,
    "state": "covered",
    "hits": "2"
  },
  {
    "id": "declaration/4/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 25,
    "state": "covered",
    "hits": "2"
  },
  {
    "id": "declaration/4/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/condition/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 25,
    "state": "covered",
    "hits": "3"
  },
  {
    "id": "declaration/4/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/condition/decision/skip-right",
    "outcome": "skip-right",
    "line": 25,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/4/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 26,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/4/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 26,
    "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": "record-declaration",
    "line": 3
  }
]