diff --git a/src/vectorcode/chunking.py b/src/vectorcode/chunking.py index ef13e8c0..dbcd0a7e 100644 --- a/src/vectorcode/chunking.py +++ b/src/vectorcode/chunking.py @@ -85,7 +85,7 @@ def __init__(self, config: Optional[Config] = None) -> None: super().__init__(config) def chunk(self, data: TextIOWrapper) -> Generator[Chunk, None, None]: - logger.info("Started chunking using FileChunker.", data.name) + logger.info("Started chunking %s using FileChunker.", data.name) lines = data.readlines() if len(lines) == 0: return diff --git a/src/vectorcode/common.py b/src/vectorcode/common.py index d5a31954..231b8290 100644 --- a/src/vectorcode/common.py +++ b/src/vectorcode/common.py @@ -5,7 +5,6 @@ import socket import subprocess import sys -import traceback from typing import AsyncGenerator import chromadb @@ -159,9 +158,8 @@ def get_embedding_function(configs: Config) -> chromadb.EmbeddingFunction | None "\nFor errors caused by missing dependency, consult the documentation of pipx (or whatever package manager that you installed VectorCode with) for instructions to inject libraries into the virtual environment." ) logger.error( - f"Failed to use {configs.embedding_function} with the following error:", + f"Failed to use {configs.embedding_function} with following error.", ) - logger.error(traceback.format_exc()) raise diff --git a/src/vectorcode/main.py b/src/vectorcode/main.py index b930f4f7..b8f15aab 100644 --- a/src/vectorcode/main.py +++ b/src/vectorcode/main.py @@ -61,7 +61,7 @@ async def async_main(): case CliAction.chunks: from vectorcode.subcommands import chunks - return_val = await chunks(final_configs) + return await chunks(final_configs) case CliAction.hooks: logger.warning( "`vectorcode hooks` has been deprecated and will be removed in 0.7.0." @@ -109,9 +109,8 @@ async def async_main(): from vectorcode.subcommands import clean return_val = await clean(final_configs) - except Exception as e: + except Exception: return_val = 1 - traceback.print_exception(e, file=sys.stderr) logger.error(traceback.format_exc()) finally: if server_process is not None: diff --git a/src/vectorcode/subcommands/query/reranker/__init__.py b/src/vectorcode/subcommands/query/reranker/__init__.py index 64b67821..466e96f3 100644 --- a/src/vectorcode/subcommands/query/reranker/__init__.py +++ b/src/vectorcode/subcommands/query/reranker/__init__.py @@ -41,13 +41,11 @@ class CustomReranker(RerankerBase): if issubclass(cls, RerankerBase): if __supported_rerankers.get(cls.__name__): error_message = f"{cls.__name__} has been registered." - logger.error(error_message) raise AttributeError(error_message) __supported_rerankers[cls.__name__] = cls return cls else: error_message = f'{cls} should be a subclass of "RerankerBase"' - logger.error(error_message) raise TypeError(error_message) @@ -66,16 +64,7 @@ def get_reranker(configs: Config) -> RerankerBase: ): return __supported_rerankers[configs.reranker].create(configs) - # TODO: replace the following with an Exception before the release of 0.6.0. - logger.warning( - f""""reranker" option should be set to one of the following: {list(i.__name__ for i in get_available_rerankers())}. -To choose a CrossEncoderReranker model, you can set the "model_name_or_path" key in the "reranker_params" option to the name/path of the model. -To use NaiveReranker, set the "reranker" option to "NaiveReranker". -The old configuration syntax will be DEPRECATED in v0.6.0 - """ - ) if not configs.reranker: return NaiveReranker(configs) else: - logger.error(f"{configs.reranker} is not a valid reranker type!") raise RerankerInitialisationError() diff --git a/tests/test_main.py b/tests/test_main.py index 8b990684..d9d688b5 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -373,10 +373,9 @@ async def test_async_main_exception_handling(monkeypatch): mock_query = AsyncMock(side_effect=Exception("Test Exception")) monkeypatch.setattr("vectorcode.subcommands.query", mock_query) - with patch("sys.stderr.write") as mock_stderr: - return_code = await async_main() - assert return_code == 1 - mock_stderr.assert_called() + with patch("vectorcode.main.logger") as mock_logger: + assert await async_main() == 1 + mock_logger.error.assert_called_once() @pytest.mark.asyncio