Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store exception traceback in logs f pipeline fails #331

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions eogrow/core/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import logging
import time
import traceback
import uuid
from typing import Any, TypeVar

import fs
import ray

from eolearn.core import CreateEOPatchTask, EOExecutor, EONode, EOWorkflow, LoadTask, SaveTask, WorkflowResults
Expand Down Expand Up @@ -255,6 +257,14 @@ def run(self) -> None:

if failed and self.config.raise_on_failure:
raise PipelineExecutionError(f"Pipeline failed some executions. Check {log_folder}.")
except Exception as e:
# store any exception info you can
failure_log_path = fs.path.join(
self.logging_manager.get_pipeline_logs_folder(self.current_execution_name), "failure.log"
)
with self.storage.filesystem.open(failure_log_path, mode="w") as log_file:
log_file.writelines(traceback.format_exc())
raise e
finally:
self.logging_manager.stop_logging(root_logger, handlers)

Expand Down
19 changes: 19 additions & 0 deletions tests/core/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import os
from contextlib import suppress
from pathlib import Path
from typing import List, Tuple, Union

import pytest
Expand Down Expand Up @@ -98,6 +100,23 @@ def test_get_patch_list_filtration_error(test_subset: List[Union[int, str]], sim
pipeline.get_patch_list()


def test_pipeline_logs_exception(simple_config_filename: str) -> None:
def cookie_alarm():
raise RuntimeError("Oh no, someone stole my cookie! :(")

config = interpret_config_from_path(simple_config_filename)
pipeline = SimplePipeline.from_raw_config(config)
pipeline.run_procedure = cookie_alarm

with suppress(RuntimeError):
pipeline.run()

log_folder = pipeline.logging_manager.get_pipeline_logs_folder(pipeline.current_execution_name, full_path=True)
log_path = Path(log_folder) / "failure.log"
assert log_path.exists()
assert "Oh no, someone stole my cookie! :(" in log_path.read_text()


@pytest.mark.parametrize("fail", [True, False])
@pytest.mark.parametrize("raise_on_failure", [True, False])
def test_pipeline_raises_on_failure(fail: bool, raise_on_failure: bool, simple_config_filename: str):
Expand Down
Loading