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

Added proper errors handling for config and fixed multiple logger instances being created #226

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

rohittp0
Copy link
Contributor

Changes

  • Fixed multiple logger instances being created for a single log output file
  • Updated the route_logger to directly access logger instead of requiring an additional parameter
  • Added proper error message with possible fix for missing / incorrect config.toml
  • Added warning and steps to fix for missing optional key in config.toml
  • Added exit with error for missing required keys

Missing Key

Before

Traceback (most recent call last):
  File "/Users/rohit/Data/Other/devika/devika.py", line 227, in <module>
    init_devika()
  File "/Users/rohit/Data/Other/devika/src/init.py", line 11, in init_devika
    sqlite_db = config.get_sqlite_db()
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rohit/Data/Other/devika/src/config.py", line 44, in get_sqlite_db
    return environ.get("SQLITE_DB_PATH", self.config["STORAGE"]["SQLITE_DB"])
                                         ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'SQLITE_DB'

After

24.03.28 22:34:11: root: ERROR  : Key 'SQLITE_DB' of STORAGE.SQLITE_DB not found in config.toml using 'None' as default value
24.03.28 22:34:11: root: INFO   : To fix this, update 'config.toml' with

[STORAGE]
SQLITE_DB = "Some value"

Missing config.toml

Before

Traceback (most recent call last):
  File "/Users/rohit/Data/Other/devika/devika.py", line 16, in <module>
    from src.agents import Agent
  File "/Users/rohit/Data/Other/devika/src/agents/__init__.py", line 1, in <module>
    from .agent import Agent
  File "/Users/rohit/Data/Other/devika/src/agents/agent.py", line 1, in <module>
    from .planner import Planner
  File "/Users/rohit/Data/Other/devika/src/agents/planner/__init__.py", line 1, in <module>
    from .planner import Planner
  File "/Users/rohit/Data/Other/devika/src/agents/planner/planner.py", line 3, in <module>
    from src.llm import LLM
  File "/Users/rohit/Data/Other/devika/src/llm/__init__.py", line 1, in <module>
    from .llm import LLM
  File "/Users/rohit/Data/Other/devika/src/llm/llm.py", line 4, in <module>
    from .ollama_client import Ollama
  File "/Users/rohit/Data/Other/devika/src/llm/ollama_client.py", line 7, in <module>
    logger = Logger()
             ^^^^^^^^
  File "/Users/rohit/Data/Other/devika/src/logger.py", line 10, in __init__
    config = Config()
             ^^^^^^^^
  File "/Users/rohit/Data/Other/devika/src/config.py", line 11, in __new__
    cls._instance.config = toml.load("config.toml")
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rohit/Data/Other/devika/venv/lib/python3.11/site-packages/toml/decoder.py", line 133, in load
    with io.open(_getpath(f), encoding='utf-8') as ffile:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'config.toml'

Process finished with exit code 1

After

24.03.28 22:37:54: root: FATAL  : Configuration file '/Users/rohit/Data/Other/devika/config.toml' not found
24.03.28 22:37:54: root: INFO   : Did you forget to create 'config.toml' file at the project root ( /Users/rohit/Data/Other/devika )?
24.03.28 22:37:54: root: INFO   : Checkout 'config.example.toml' and https://toml.io/en/ for more information on TOML.

Process finished with exit code 1

@ARajgor
Copy link
Collaborator

ARajgor commented Apr 6, 2024

fetch the latest changes and resolve the conflicts.

@rohittp0
Copy link
Contributor Author

rohittp0 commented Apr 8, 2024

@ARajgor The conflicts has been resolved

src/logger.py Outdated Show resolved Hide resolved
devika.py Outdated Show resolved Hide resolved
rohittp0 and others added 2 commits April 16, 2024 16:43
Co-authored-by: Israel Antonio Rosales Laguan <israellaguan@gmail.com>
src/logger.py Outdated Show resolved Hide resolved
rohittp0 and others added 2 commits April 16, 2024 20:02
Co-authored-by: Israel Antonio Rosales Laguan <israellaguan@gmail.com>
@rohittp0
Copy link
Contributor Author

@Israel-Laguan If the review is done, can this be merged? I can understand you must be very busy but conflicts are piling on as new commits are being pushed to the main branch. :)

@Israel-Laguan
Copy link

Yeah I think it can be merged, no problem from my side

@rohittp0
Copy link
Contributor Author

@Israel-Laguan Can you merge it as I don't have write access

return cls._instance

cls._instance = super().__new__(cls)
cls._logger = LogInit(pathName="logs/core.log", console=True, colors=True)
Copy link
Collaborator

@ARajgor ARajgor Apr 19, 2024

Choose a reason for hiding this comment

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

log path is fetch from config file. we are saving it in data/logs/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't fetch from config file here as it needs to handle the case when the config file is missing

Copy link
Collaborator

Choose a reason for hiding this comment

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

sample.config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be better of we can avoid IO here as there won't be any way to handle any errors as not even the logging will be enabled. Like what if the user incorrectly edits the sample.config and there is some mistake.

If you are sure that this won't be a concern I can update the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or if the user renamed config.example to config etc

Copy link
Collaborator

Choose a reason for hiding this comment

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

also why creating new logger? just fetch from logger file and log it. so it will be in one file and simple

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logger will not be initialised at this point, importing here will cause cycling import

@rohittp0
Copy link
Contributor Author

rohittp0 commented May 2, 2024

@Israel-Laguan any updates ?

@Israel-Laguan
Copy link

Bro I don't have write access either

@Israel-Laguan
Copy link

@ARajgor would be able to help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants