Skip to content

Commit

Permalink
Fix rpc signature error
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Mar 3, 2024
1 parent 33c4272 commit 05e6c09
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 20 deletions.
2 changes: 1 addition & 1 deletion javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imjoy-rpc",
"version": "0.5.47",
"version": "0.5.48",
"description": "Remote procedure calls for ImJoy.",
"module": "index.js",
"types": "index.d.ts",
Expand Down
10 changes: 8 additions & 2 deletions javascript/src/hypha/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,11 @@ export class RPC extends MessageEmitter {
};
} else if (aObject instanceof Error) {
console.error(aObject);
bObject = { _rtype: "error", _rvalue: aObject.toString() };
bObject = {
_rtype: "error",
_rvalue: aObject.toString(),
_rtrace: aObject.stack
};
}
// send objects supported by structure clone algorithm
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
Expand Down Expand Up @@ -1405,7 +1409,9 @@ export class RPC extends MessageEmitter {
bObject = aObject;
}
} else if (aObject._rtype === "error") {
bObject = new Error(aObject._rvalue);
bObject = new Error(
"RemoteError: " + aObject._rvalue + "\n" + (aObject._rtrace || "")
);
} else if (aObject._rtype === "typedarray") {
const arraytype = dtypeToTypedArray[aObject._rdtype];
if (!arraytype)
Expand Down
2 changes: 1 addition & 1 deletion python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

.vscode

.pypirc
*.DS_Store
*.app
node_modules
Expand Down
2 changes: 1 addition & 1 deletion python/imjoy_rpc/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.5.47"
"version": "0.5.48"
}
41 changes: 33 additions & 8 deletions python/imjoy_rpc/hypha/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def index_object(obj, ids):
return index_object(_obj, ids[1:])


class RemoteException(Exception):
"""Represent a remote exception."""

pass


class Timer:
"""Represent a timer."""

Expand Down Expand Up @@ -817,12 +823,17 @@ def handle_result(fut):
remote_method.__rpc_object__ = (
encoded_method.copy()
) # pylint: disable=protected-access
make_signature(
remote_method,
name=method_id.split(".")[-1],
doc=encoded_method.get("_rdoc"),
sig=encoded_method.get("_rsig"),
)
try:
make_signature(
remote_method,
name=method_id.split(".")[-1],
doc=encoded_method.get("_rdoc"),
sig=encoded_method.get("_rsig"),
)
except Exception as exp:
logger.warning(
"Failed to generate signature for method: %s, error: %s", method_id, exp
)
return remote_method

def _log(self, info):
Expand Down Expand Up @@ -1193,7 +1204,16 @@ def _encode(
}

elif isinstance(a_object, Exception):
b_object = {"_rtype": "error", "_rvalue": str(a_object)}
exc_traceback = "".join(
traceback.format_exception(
etype=type(a_object), value=a_object, tb=a_object.__traceback__
)
)
b_object = {
"_rtype": "error",
"_rvalue": str(a_object),
"_rtrace": exc_traceback,
}
elif isinstance(a_object, memoryview):
b_object = {"_rtype": "memoryview", "_rvalue": a_object.tobytes()}
elif isinstance(
Expand Down Expand Up @@ -1364,7 +1384,12 @@ def _decode(
)
)
elif a_object["_rtype"] == "error":
b_object = Exception(a_object["_rvalue"])
b_object = RemoteException(
"RemoteError:"
+ a_object["_rvalue"]
+ "\n"
+ (a_object.get("_rtrace") if a_object.get("_rtrace") else "")
)
else:
# make sure all the interface functions are decoded
temp = a_object["_rtype"]
Expand Down
16 changes: 10 additions & 6 deletions python/imjoy_rpc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,20 +908,24 @@ def elfinder_listdir(path):
req = _sync_xhr_get(url)
if req.status in [200, 206]:
file_list = json.loads(req.response.to_py().tobytes().decode())
if 'list' in file_list:
return file_list['list']
if "list" in file_list:
return file_list["list"]
else:
return []
else:
raise FileNotFoundError(f"Directory '{path}' could not be found, HTTP status code: {req.status}")
raise FileNotFoundError(
f"Directory '{path}' could not be found, HTTP status code: {req.status}"
)
else:
req = Request(url)
response = urlopen(req)
if response.getcode() == 200:
file_list = json.loads(response.read().decode())
if 'list' in file_list:
return file_list['list']
if "list" in file_list:
return file_list["list"]
else:
return []
else:
raise FileNotFoundError(f"Directory '{path}' could not be found, HTTP status code: {response.getcode()}")
raise FileNotFoundError(
f"Directory '{path}' could not be found, HTTP status code: {response.getcode()}"
)

0 comments on commit 05e6c09

Please sign in to comment.