Skip to content
Closed
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
11 changes: 1 addition & 10 deletions cognite/extractorutils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import contextlib
import logging
import os
import sys
from collections.abc import Callable
from dataclasses import is_dataclass
from enum import Enum
Expand All @@ -38,7 +37,6 @@
ConfigResolver,
StateStoreConfig,
)
from cognite.extractorutils.exceptions import InvalidConfigError
from cognite.extractorutils.metrics import BaseMetrics
from cognite.extractorutils.statestore import (
AbstractStateStore,
Expand Down Expand Up @@ -315,14 +313,7 @@ def __enter__(self) -> "Extractor":
else:
dotenv_message = "No .env file imported when using Cognite Functions"

try:
self._initial_load_config(override_path=self.config_file_path)
except InvalidConfigError as e:
print( # noqa: T201
"Critical error: Could not read config file", file=sys.stderr
)
print(str(e), file=sys.stderr) # noqa: T201
sys.exit(1)
self._initial_load_config(override_path=self.config_file_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to use the logger for this? like what if we use the logger and log with the level of Exception?

I am sure this will work but I want to understand how this changes between the older implementataion? Were you able to test out a build maybe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also were you able to check if this change helps with the newer unstable module as well?


if not self.configured_logger:
self.config.logger.setup_logging()
Expand Down
15 changes: 15 additions & 0 deletions tests/tests_unit/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from cognite.client.data_classes import ExtractionPipeline, ExtractionPipelineRun
from cognite.extractorutils import Extractor
from cognite.extractorutils.configtools import BaseConfig, StateStoreConfig
from cognite.extractorutils.exceptions import InvalidConfigError
from cognite.extractorutils.statestore import LocalStateStore, NoStateStore


Expand Down Expand Up @@ -277,3 +278,17 @@ def validate_long_message(run: ExtractionPipelineRun) -> None:

extractor.extraction_pipeline = None
# assert False


def test_enter_raises_on_invalid_config() -> None:
extractor = Extractor(
name="test_invalid_config",
description="description",
config_class=ConfigWithStates,
config_file_path="tests/tests_unit/dummyconfig.yaml",
)
with (
patch.object(extractor, "_initial_load_config", side_effect=InvalidConfigError("bad config")),
pytest.raises(InvalidConfigError, match="bad config"),
):
extractor.__enter__()
Loading