diff --git a/doc/changelog.d/937.maintenance.md b/doc/changelog.d/937.maintenance.md new file mode 100644 index 000000000..f924fee22 --- /dev/null +++ b/doc/changelog.d/937.maintenance.md @@ -0,0 +1 @@ +Code maintenance \ No newline at end of file diff --git a/src/ansys/mechanical/core/embedding/initializer.py b/src/ansys/mechanical/core/embedding/initializer.py index ddd28350d..130047d1f 100644 --- a/src/ansys/mechanical/core/embedding/initializer.py +++ b/src/ansys/mechanical/core/embedding/initializer.py @@ -164,8 +164,12 @@ def initialize(version: int = None): __check_for_mechanical_env() # checks for mechanical-env in linux embedding global INITIALIZED_VERSION - if INITIALIZED_VERSION != None: - assert INITIALIZED_VERSION == version + if INITIALIZED_VERSION is not None: + if INITIALIZED_VERSION != version: + raise ValueError( + f"Initialized version {INITIALIZED_VERSION} " + f"does not match the expected version {version}." + ) return if version == None: diff --git a/src/ansys/mechanical/core/embedding/viz/utils.py b/src/ansys/mechanical/core/embedding/viz/utils.py index 9ccb570f0..93ed55171 100644 --- a/src/ansys/mechanical/core/embedding/viz/utils.py +++ b/src/ansys/mechanical/core/embedding/viz/utils.py @@ -41,7 +41,8 @@ def _reshape_3cols(arr: np.array, name: str = "array"): """ err = f"{name} must be of the form (x0,y0,z0,x1,y1,z1,...,xn,yn,zn).\ Given {name} are not divisible by 3!" - assert arr.size % 3 == 0, err + if arr.size % 3 != 0: + raise ValueError(err) numrows = int(arr.size / 3) numcols = 3 arr = np.reshape(arr, (numrows, numcols)) diff --git a/src/ansys/mechanical/core/mechanical.py b/src/ansys/mechanical/core/mechanical.py index d7d6b9368..56c5f86dd 100644 --- a/src/ansys/mechanical/core/mechanical.py +++ b/src/ansys/mechanical/core/mechanical.py @@ -508,8 +508,8 @@ def name(self): return f"GRPC_{self._channel._channel._channel.target().decode()}" else: return f"GRPC_{self._channel._channel.target().decode()}" - except Exception: # pragma: no cover - pass + except Exception as e: # pragma: no cover + LOG.error(f"Error getting the Mechanical instance name: {str(e)}") return f"GRPC_instance_{id(self)}" # pragma: no cover diff --git a/src/ansys/mechanical/core/pool.py b/src/ansys/mechanical/core/pool.py index 94a5c2b7f..33f9eec26 100644 --- a/src/ansys/mechanical/core/pool.py +++ b/src/ansys/mechanical/core/pool.py @@ -583,8 +583,8 @@ def threaded_exit(index, instance_local): if instance_local: try: instance_local.exit() - except: # pragma: no cover - pass + except Exception as e: # pragma: no cover + LOG.error(f"Error while exiting instance {str(instance_local)}: {str(e)}") self._instances[index] = None LOG.debug(f"Exited instance: {str(instance_local)}") diff --git a/src/ansys/mechanical/core/run.py b/src/ansys/mechanical/core/run.py index 4b12f282b..bb6b9e3ea 100644 --- a/src/ansys/mechanical/core/run.py +++ b/src/ansys/mechanical/core/run.py @@ -54,7 +54,8 @@ async def _read_and_display(cmd, env, do_display: bool): } while tasks: done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED) - assert done + if not done: + raise RuntimeError("Subprocess read failed: No tasks completed.") for future in done: buf, stream, display = tasks.pop(future) line = future.result()