Skip to content

Commit 0c04a2b

Browse files
committed
remove redundant error logs
1 parent 1028dda commit 0c04a2b

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

packages/jupyter-ai/jupyter_ai/personas/persona_manager.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ def _init_persona_classes(self) -> None:
8181
# On exception, log an error and continue.
8282
# This does not stop the surrounding `for` loop. If a persona
8383
# fails to load, it should not halt other personas from loading.
84-
self.log.error(
84+
self.log.exception(
8585
f" - Unable to load AI persona from entry point `{persona_ep.name}` due to an exception printed below."
8686
)
87-
self.log.exception(e)
8887
continue
8988

9089
if len(persona_classes) > 0:
@@ -116,26 +115,35 @@ def _init_personas(self) -> dict[str, BasePersona]:
116115

117116
personas: dict[str, BasePersona] = {}
118117
for Persona in persona_classes:
119-
persona = Persona(
120-
ychat=self.ychat,
121-
manager=self,
122-
config=self.config_manager,
123-
log=self.log,
124-
)
118+
try:
119+
persona = Persona(
120+
ychat=self.ychat,
121+
manager=self,
122+
config=self.config_manager,
123+
log=self.log,
124+
)
125+
except Exception as e:
126+
self.log.exception(
127+
f"The persona provided by `{Persona.__module__}` "
128+
"raised an exception while initializing, "
129+
"printed below."
130+
)
131+
continue
132+
125133
if persona.id in personas:
126134
class_name = persona.__class__.__name__
127135
self.log.warning(
128136
f" - WARNING: Skipping persona '{persona.name}' from '{persona.__module__}' because another persona has an identical ID '{persona.id}'. "
129137
+ f"Personas must all have unique IDs. Please rename the persona class from '{class_name}' to something unique to dismiss this warning."
130138
)
131139
continue
132-
else:
133-
self.log.info(
134-
f" - Initialized persona '{persona.name}' (ID: '{persona.id}')."
135-
)
136-
personas[persona.id] = persona
137140

138-
elapsed_time_ms = (time_ns() - start_time_ns) // 1000
141+
self.log.info(
142+
f" - Initialized persona '{persona.name}' (ID: '{persona.id}')."
143+
)
144+
personas[persona.id] = persona
145+
146+
elapsed_time_ms = (time_ns() - start_time_ns) // 1_000_000
139147
self.log.info(
140148
f"SUCCESS: Initialized {len(personas)} AI personas for chat room '{self.ychat.get_id()}'. Time elapsed: {elapsed_time_ms}ms."
141149
)

0 commit comments

Comments
 (0)