Skip to content

Commit

Permalink
Raise exception in connect and element when failed
Browse files Browse the repository at this point in the history
- The shell only generates an error message when an attempt to connect
two objects via message fails. This caused hard to debug errors. Now
the wrapper function raises RuntimeError in such case.

- `element(path)` returned the roor element when `path` does not
exist, again causing hard to find bugs. This now raises RuntimeError.
  • Loading branch information
subhacom committed Dec 16, 2024
1 parent 19547cc commit 8f0eaf7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ https://github.com/BhallaLab/moose-examples.
# Build

To build `pymoose`, follow instructions given in
[INSTALLATION.md](INSTALLATION.md) and for platform specific
[INSTALLATION.md](INSTALL.md) and for platform specific
information see:
- Linux: [UbuntuBuild.md](UbuntuBuild.md)
- MacOSX: [AppleM1Build.md](AppleM1Build.md)
Expand Down
7 changes: 6 additions & 1 deletion python/moose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ def connect(src, srcfield, dest, destfield, msgtype="Single"):
"""
src = _moose.element(src)
dest = _moose.element(dest)
return src.connect(srcfield, dest, destfield, msgtype)
msg = src.connect(srcfield, dest, destfield, msgtype)
if msg.name == '/':
raise RuntimeError(f'Could not connect {src}.{srcfield} with {dest}.{destfield}')
return msg


def delete(arg):
Expand Down Expand Up @@ -239,6 +242,8 @@ def element(arg):
MOOSE element (object) corresponding to the `arg` converted to write
subclass.
"""
if not _moose.exists(arg):
raise RuntimeError(f'{arg}: element at path does not exist')
return _moose.element(arg)


Expand Down

0 comments on commit 8f0eaf7

Please sign in to comment.