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
3
Three, 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
7
refusing a state point is *routine* -- it means "ask a slower backend" -- while
8
any other failure is a real error that must not be swallowed.
9
"""
10
11
from
__future__
import
annotations
12
13
14
class
PropertyError
(Exception):
15
"""Base for every failure in the property layer."""
16
17
18
class
OutOfRange
(
PropertyError
):
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
34
class
UnsupportedProperty
(
PropertyError
):
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
50
class
UnknownFluid
(
PropertyError
):
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
feedtwin.props.errors.OutOfRange
Definition
errors.py:18
feedtwin.props.errors.OutOfRange.fluid
fluid
Definition
errors.py:30
feedtwin.props.errors.OutOfRange.__init__
None __init__(self, str backend, str fluid, str detail)
Definition
errors.py:27
feedtwin.props.errors.OutOfRange.backend
backend
Definition
errors.py:29
feedtwin.props.errors.OutOfRange.detail
detail
Definition
errors.py:31
feedtwin.props.errors.PropertyError
Definition
errors.py:14
feedtwin.props.errors.UnknownFluid
Definition
errors.py:50
feedtwin.props.errors.UnknownFluid.__init__
None __init__(self, str name, list[str] known)
Definition
errors.py:53
feedtwin.props.errors.UnknownFluid.name
name
Definition
errors.py:63
feedtwin.props.errors.UnsupportedProperty
Definition
errors.py:34
feedtwin.props.errors.UnsupportedProperty.backend
backend
Definition
errors.py:46
feedtwin.props.errors.UnsupportedProperty.prop
prop
Definition
errors.py:47
feedtwin.props.errors.UnsupportedProperty.__init__
None __init__(self, str backend, str prop)
Definition
errors.py:44
lib
feedtwin
feedtwin
props
errors.py
Generated by
1.15.0