Skip to content

Commit 728c82e

Browse files
committed
Improved error handling in Pipelex.make() with meaningful error classes.
1 parent 604cb8e commit 728c82e

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

pipelex/pipelex.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(
8383
self.pipelex_hub.setup_config(config_cls=config_cls or PipelexConfig)
8484
except ValidationError as exc:
8585
error_msg = format_pydantic_validation_error(exc)
86-
raise PipelexConfigError(f"Error because of: {error_msg}") from exc
86+
raise PipelexConfigError(f"Could not setup config because of: {error_msg}") from exc
8787

8888
for extra_env_file in get_config().pipelex.extra_env_files:
8989
load_dotenv(dotenv_path=extra_env_file, override=True)
@@ -202,15 +202,15 @@ def setup_libraries(self):
202202
self.pipelex_hub.set_llm_deck_provider(llm_deck_provider=llm_deck)
203203
except ValidationError as exc:
204204
error_msg = format_pydantic_validation_error(exc)
205-
raise PipelexSetupError(f"Error because of: {error_msg}") from exc
205+
raise PipelexSetupError(f"Could not setup libraries because of: {error_msg}") from exc
206206
log.debug(f"{PACKAGE_NAME} version {PACKAGE_VERSION} setup libraries done for {get_config().project_name}")
207207

208208
def validate_libraries(self):
209209
try:
210210
self.library_manager.validate_libraries()
211211
except ValidationError as exc:
212212
error_msg = format_pydantic_validation_error(exc)
213-
raise PipelexSetupError(f"Error because of: {error_msg}") from exc
213+
raise PipelexSetupError(f"Could not validate libraries because of: {error_msg}") from exc
214214
log.debug(f"{PACKAGE_NAME} version {PACKAGE_VERSION} validate libraries done for {get_config().project_name}")
215215

216216
def teardown(self):
@@ -260,22 +260,22 @@ def make(
260260
Initialized Pipelex instance.
261261
262262
Raises:
263-
ValueError: If both relative_config_folder_path and absolute_config_folder_path are provided.
264-
RuntimeError: If frame inspection fails when using relative paths with from_file=True.
263+
PipelexSetupError: If both relative_config_folder_path and absolute_config_folder_path are provided.
264+
Or if frame inspection fails when using relative paths with from_file=True.
265265
266266
Note:
267267
If neither path is provided, defaults to "./pipelex_libraries".
268268
"""
269269
if relative_config_folder_path is not None and absolute_config_folder_path is not None:
270-
raise ValueError("Cannot specify both relative_config_folder_path and absolute_config_folder_path")
270+
raise PipelexSetupError("Cannot specify both relative_config_folder_path and absolute_config_folder_path")
271271

272272
if relative_config_folder_path is not None:
273273
if from_file:
274274
current_frame = inspect.currentframe()
275275
if current_frame is None:
276-
raise RuntimeError("Failed to get current frame")
276+
raise PipelexSetupError("Could not find relative config folder path because of: Failed to get current frame")
277277
if current_frame.f_back is None:
278-
raise RuntimeError("Failed to get caller frame")
278+
raise PipelexSetupError("Could not find relative config folder path because of: Failed to get caller frame")
279279
caller_file = current_frame.f_back.f_code.co_filename
280280
caller_dir = os.path.dirname(os.path.abspath(caller_file))
281281
config_folder_path = os.path.abspath(os.path.join(caller_dir, relative_config_folder_path))

0 commit comments

Comments
 (0)