|
2 | 2 | import re |
3 | 3 | import subprocess |
4 | 4 | import time |
| 5 | +import traceback |
5 | 6 | from collections.abc import Callable |
6 | 7 | from pathlib import Path |
7 | 8 | from typing import TypedDict |
@@ -265,19 +266,18 @@ def get_tree_from_db(self): |
265 | 266 | tree = get_tree_struct(db.session, webpages) |
266 | 267 | # If the tree is empty, load from the repository |
267 | 268 | if not tree or ( |
268 | | - tree.get("children") and not tree.get("parent_id") |
| 269 | + not tree.get("children") and not tree.get("parent_id") |
269 | 270 | ): |
270 | 271 | msg = ( |
271 | 272 | "Reloading incomplete tree root " |
272 | | - f"{self.repository_uri}." |
| 273 | + f"{self.repository_uri}. {tree}" |
273 | 274 | ) |
274 | 275 | self.logger.info( |
275 | 276 | msg, |
276 | 277 | ) |
277 | 278 | tree = self.get_new_tree() |
278 | 279 | return tree |
279 | | - # Raise an error if the project does not exist. |
280 | | - raise SiteRepositoryError("Invalid project_id. Unable to load tree.") |
| 280 | + return None |
281 | 281 |
|
282 | 282 | def get_tree(self, no_cache: bool = False): |
283 | 283 | """Get the tree from the cache or load a new tree to cache and db.""" |
@@ -403,14 +403,15 @@ def get_tree_sync(self, no_cache: bool = False): |
403 | 403 | self.invalidate_cache() |
404 | 404 |
|
405 | 405 | # Load the tree from database |
406 | | - try: |
407 | | - tree = self.get_tree_from_db() |
| 406 | + if tree := self.get_tree_from_db(): |
408 | 407 | self.logger.info(f"Tree refreshed for {self.repository_uri}") |
409 | | - # Update the cache |
410 | | - self.set_tree_in_cache(tree) |
| 408 | + try: |
| 409 | + # Update the cache |
| 410 | + self.set_tree_in_cache(tree) |
| 411 | + except Exception as e: |
| 412 | + self.logger.exception(traceback.format_exc()) |
| 413 | + self.logger.error(f"Unable to save tree to cache: {e}") |
411 | 414 | return tree |
412 | | - except Exception as e: |
413 | | - self.logger.error(f"Error loading tree: {e}") |
414 | 415 |
|
415 | 416 | # Or just return an empty tree |
416 | 417 | return { |
|
0 commit comments