Skip to content

Commit a4600ef

Browse files
committed
Update Pydantic Logging
1 parent c4eb8a5 commit a4600ef

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

cppython/core/resolution.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""Data conversion routines"""
22

3+
import logging
34
from pathlib import Path
45
from typing import Any, cast
56

67
from pydantic import BaseModel, DirectoryPath, ValidationError
78

8-
from cppython.core.exception import ConfigError, ConfigException
9+
from cppython.core.exception import ConfigException
910
from cppython.core.plugin_schema.generator import Generator, GeneratorPluginGroupData
1011
from cppython.core.plugin_schema.provider import Provider, ProviderPluginGroupData
1112
from cppython.core.plugin_schema.scm import SCM, SCMPluginGroupData
@@ -257,7 +258,12 @@ def resolve_model[T: BaseModel](model: type[T], data: dict[str, Any]) -> T:
257258
# BaseModel is setup to ignore extra fields
258259
return model(**data)
259260
except ValidationError as e:
260-
new_errors: list[ConfigError] = []
261-
for error in e.errors():
262-
new_errors.append(ConfigError(message=error['msg']))
263-
raise ConfigException('The input project failed', new_errors) from e
261+
# Log the raw ValidationError for debugging
262+
logging.getLogger('cppython').debug('ValidationError details: %s', e.errors())
263+
264+
if e.errors():
265+
formatted_errors = '\n'.join(f"Field '{error['loc'][0]}': {error['msg']}" for error in e.errors())
266+
else:
267+
formatted_errors = 'An unknown validation error occurred.'
268+
269+
raise ConfigException(f'The input project failed validation:\n{formatted_errors}', []) from e

cppython/project.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from cppython.core.resolution import resolve_model
1010
from cppython.core.schema import Interface, ProjectConfiguration, PyProject
1111
from cppython.schema import API
12+
from cppython.utility.exception import ProcessError
1213

1314

1415
class Project(API):
@@ -29,8 +30,9 @@ def __init__(
2930
try:
3031
pyproject = resolve_model(PyProject, pyproject_data)
3132
except ConfigException as error:
32-
self.logger.error(error, exc_info=True)
33-
raise SystemExit(1) from None
33+
# Log the exception message explicitly
34+
self.logger.error('Configuration error:\n%s', error, exc_info=False)
35+
raise SystemExit('Error: Invalid configuration. Please check your pyproject.toml.') from None
3436

3537
if not pyproject.tool or not pyproject.tool.cppython:
3638
self.logger.info("The pyproject.toml file doesn't contain the `tool.cppython` table")
@@ -69,9 +71,12 @@ def install(self) -> None:
6971

7072
try:
7173
self._data.plugins.provider.install()
74+
except ProcessError as error:
75+
self.logger.error('Installation failed: %s', error.error)
76+
raise SystemExit('Error: Provider installation failed. Please check the logs.') from None
7277
except Exception as exception:
73-
self.logger.error('Provider %s failed to install', self._data.plugins.provider.name())
74-
raise exception
78+
self.logger.error('Unexpected error during installation: %s', str(exception))
79+
raise SystemExit('Error: An unexpected error occurred during installation.') from None
7580

7681
self._data.sync()
7782

@@ -93,8 +98,11 @@ def update(self) -> None:
9398

9499
try:
95100
self._data.plugins.provider.update()
101+
except ProcessError as error:
102+
self.logger.error('Update failed: %s', error.error)
103+
raise SystemExit('Error: Provider update failed. Please check the logs.') from None
96104
except Exception as exception:
97-
self.logger.error('Provider %s failed to update', self._data.plugins.provider.name())
98-
raise exception
105+
self.logger.error('Unexpected error during update: %s', str(exception))
106+
raise SystemExit('Error: An unexpected error occurred during update.') from None
99107

100108
self._data.sync()

0 commit comments

Comments
 (0)