STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
errors.py
Go to the documentation of this file.
1"""Property-layer errors.
2
3Three, and the distinction between them is what makes the fallback chain in
4:mod:`feedtwin.props.fluid` possible rather than a pile of ``except Exception``.
5
6``OutOfRange`` in particular is the load-bearing one: a fast tabulated backend
7refusing a state point is *routine* -- it means "ask a slower backend" -- while
8any other failure is a real error that must not be swallowed.
9"""
10
11from __future__ import annotations
12
13
14class PropertyError(Exception):
15 """Base for every failure in the property layer."""
16
17
19 """A backend was asked for a state point outside its validity envelope.
20
21 Routine, not exceptional: tabulated backends cover a bounded region and
22 raising here is how they say so. The fluid's backend chain catches this and
23 tries the next backend. It is a bug to treat it as fatal without first
24 exhausting the chain, and a worse bug to catch it and return a number.
25 """
26
27 def __init__(self, backend: str, fluid: str, detail: str) -> None:
28 super().__init__(f"{backend} has no coverage for {fluid}: {detail}")
29 self.backend = backend
30 self.fluid = fluid
31 self.detail = detail
32
33
35 """A backend cannot compute a property that another backend can.
36
37 Real and specific: CoolProp's BICUBIC tables implement density, viscosity
38 and conductivity but not ``compressibility_factor``. Like OutOfRange this
39 is answered by falling through the chain rather than by failing the call --
40 but unlike OutOfRange it is a property of the backend, not of the state, so
41 it can be answered once instead of per state point.
42 """
43
44 def __init__(self, backend: str, prop: str) -> None:
45 super().__init__(f"backend {backend!r} does not implement {prop!r}")
46 self.backend = backend
47 self.prop = prop
48
49
51 """No species by that name or alias is registered."""
52
53 def __init__(self, name: str, known: list[str]) -> None:
54 import difflib
55
56 close = difflib.get_close_matches(name.lower(), known, n=3, cutoff=0.4)
57 hint = f" Did you mean {', '.join(repr(c) for c in close)}?" if close else ""
58 super().__init__(
59 f"unknown fluid {name!r}.{hint} Registered: "
60 f"{', '.join(sorted(known))}. Add it to feedtwin/props/species.toml, "
61 "or register it at runtime with feedtwin.props.register_species()."
62 )
63 self.name = name
None __init__(self, str backend, str fluid, str detail)
Definition errors.py:27
None __init__(self, str name, list[str] known)
Definition errors.py:53
None __init__(self, str backend, str prop)
Definition errors.py:44