From e6c1d3fef1e155522434624439269e5c66e3e7c7 Mon Sep 17 00:00:00 2001 From: Josue Nina Date: Fri, 3 Oct 2025 15:03:47 -0500 Subject: [PATCH 1/2] Improve error message --- lean/components/cloud/push_manager.py | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lean/components/cloud/push_manager.py b/lean/components/cloud/push_manager.py index 3f171de6..f891b9fd 100644 --- a/lean/components/cloud/push_manager.py +++ b/lean/components/cloud/push_manager.py @@ -171,6 +171,13 @@ def _get_files(self, project: Path, encryption_action: Optional[ActionType], enc :param project: the local project to push the files of """ paths = self._project_manager.get_source_files(project) + + # First validate all file sizes + for path in paths: + is_valid, error_message = self._validate_file_size(path) + if not is_valid: + self._logger.error(error_message) + if encryption_key: from lean.components.util.encryption_helper import get_appropriate_files_from_local_project organization_id = self._organization_manager.try_get_working_organization_id() @@ -276,3 +283,27 @@ def _get_cloud_project(self, project_id: int, organization_id: str) -> QCProject self._cloud_projects.append(project) return project + + def _validate_file_size(self, file_path: Path) -> (bool, str): + """Validates that a file does not exceed the 10MB limit. + + :param file_path: the path to the file being validated + :return: tuple (is_valid, error_message). + is_valid is False if the file exceeds the 10MB limit, + and error_message contains the details; + otherwise, is_valid is True and error_message is empty. + """ + max_file_size = 10 * 1024 * 1024 # 10MB in bytes + + # Get file size directly from filesystem + size_in_bytes = file_path.stat().st_size + + if size_in_bytes > max_file_size: + size_mb = size_in_bytes / (1024 * 1024) + error_msg = ( + f"The file '{file_path.name}' exceeds the 10MB limit. " + f"Current size: {size_mb:.2f}MB" + ) + return False, error_msg + + return True, '' From 9c771323c104e1e902c317231ac8e28d9cd52a97 Mon Sep 17 00:00:00 2001 From: Josue Nina Date: Mon, 6 Oct 2025 10:52:35 -0500 Subject: [PATCH 2/2] Improve error message for 413 responses --- lean/components/cloud/push_manager.py | 31 --------------------------- lean/models/errors.py | 2 ++ 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/lean/components/cloud/push_manager.py b/lean/components/cloud/push_manager.py index f891b9fd..3f171de6 100644 --- a/lean/components/cloud/push_manager.py +++ b/lean/components/cloud/push_manager.py @@ -171,13 +171,6 @@ def _get_files(self, project: Path, encryption_action: Optional[ActionType], enc :param project: the local project to push the files of """ paths = self._project_manager.get_source_files(project) - - # First validate all file sizes - for path in paths: - is_valid, error_message = self._validate_file_size(path) - if not is_valid: - self._logger.error(error_message) - if encryption_key: from lean.components.util.encryption_helper import get_appropriate_files_from_local_project organization_id = self._organization_manager.try_get_working_organization_id() @@ -283,27 +276,3 @@ def _get_cloud_project(self, project_id: int, organization_id: str) -> QCProject self._cloud_projects.append(project) return project - - def _validate_file_size(self, file_path: Path) -> (bool, str): - """Validates that a file does not exceed the 10MB limit. - - :param file_path: the path to the file being validated - :return: tuple (is_valid, error_message). - is_valid is False if the file exceeds the 10MB limit, - and error_message contains the details; - otherwise, is_valid is True and error_message is empty. - """ - max_file_size = 10 * 1024 * 1024 # 10MB in bytes - - # Get file size directly from filesystem - size_in_bytes = file_path.stat().st_size - - if size_in_bytes > max_file_size: - size_mb = size_in_bytes / (1024 * 1024) - error_msg = ( - f"The file '{file_path.name}' exceeds the 10MB limit. " - f"Current size: {size_mb:.2f}MB" - ) - return False, error_msg - - return True, '' diff --git a/lean/models/errors.py b/lean/models/errors.py index e31e7df4..12769d9f 100644 --- a/lean/models/errors.py +++ b/lean/models/errors.py @@ -26,6 +26,8 @@ def __init__(self, response, message: Optional[str] = None) -> None: if message is None: request = response.request message = f"{request.method} request to {request.url} failed with status code {response.status_code}" + if response.status_code == 413: + message += "\nThe uploaded files exceed the allowed size limit. Please upload smaller files" super().__init__(message)