Skip to content

Commit

Permalink
server: better error when un/wrap fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavidsaver committed Jul 6, 2023
1 parent c042ab0 commit 23e26ca
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/p4p/server/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ def __init__(self, op, wrap, unwrap):
self._op, self._wrap, self._unwrap = op, wrap, unwrap

def value(self):
return self._unwrap(self._op.value())
V = self._op.value()
try:
return self._unwrap(V)
except: # py3 will chain automatically, py2 won't
raise ValueError("Unable to unwrap %r with %r"%(V, self._unwrap))

def done(self, value=None, error=None):
if value is not None:
value = self._wrap(value)
try:
value = self._wrap(value)
except:
raise ValueError("Unable to wrap %r with %r"%(value, self._wrap))
self._op.done(value, error)

def __getattr__(self, key):
Expand Down Expand Up @@ -147,7 +154,11 @@ def open(self, value, nt=None, wrap=None, unwrap=None, **kws):
self._wrap = wrap or (nt and nt.wrap) or self._wrap
self._unwrap = unwrap or (nt and nt.unwrap) or self._unwrap

_SharedPV.open(self, self._wrap(value, **kws))
try:
V = self._wrap(value, **kws)
except: # py3 will chain automatically, py2 won't
raise ValueError("Unable to wrap %r with %r and %r"%(value, self._wrap, kws))
_SharedPV.open(self, V)

def post(self, value, **kws):
"""Provide an update to the Value of this PV.
Expand All @@ -159,10 +170,18 @@ def post(self, value, **kws):
Any keyword arguments are forwarded to the NT wrap() method (if applicable).
Common arguments include: timestamp= , severity= , and message= .
"""
_SharedPV.post(self, self._wrap(value, **kws))
try:
V = self._wrap(value, **kws)
except: # py3 will chain automatically, py2 won't
raise ValueError("Unable to wrap %r with %r and %r"%(value, self._wrap, kws))
_SharedPV.post(self, V)

def current(self):
return self._unwrap(_SharedPV.current(self))
V = _SharedPV.current(self)
try:
return self._unwrap()

This comment has been minimized.

Copy link
@juanfem

juanfem Jul 25, 2023

Contributor

I think line 182 should be return self._unwrap(V).
I am getting an exception like this:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/p4p/server/raw.py", line 182, in current
    return self._unwrap()
TypeError: <lambda>() missing 1 required positional argument: 'x'

This comment has been minimized.

Copy link
@mdavidsaver

mdavidsaver Jul 25, 2023

Author Member

oops, why yes it should.

except: # py3 will chain automatically, py2 won't
raise ValueError("Unable to unwrap %r with %r"%(V, self._unwrap))

def _exec(self, op, M, *args): # sub-classes will replace this
try:
Expand Down

0 comments on commit 23e26ca

Please sign in to comment.