Skip to content

Commit

Permalink
sphinx-agent: Handle unexpected config values
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Jul 16, 2024
1 parent 9a789ad commit 02649e9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/esbonio/changes/843.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The sphinx agent should no longer crash when encountering unexpected config values
1 change: 1 addition & 0 deletions lib/esbonio/esbonio/sphinx_agent/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
RoleDefinition = Tuple[str, Any, List[types.Role.TargetProvider]]

sphinx_logger = logging.getLogger(SPHINX_LOG_NAMESPACE)
logger = sphinx_logger.getChild("esbonio")
sphinx_log_setup = sphinx_logging_module.setup


Expand Down
26 changes: 18 additions & 8 deletions lib/esbonio/esbonio/sphinx_agent/handlers/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

from ..app import Database
from ..app import Sphinx
from ..app import logger
from ..types import Uri
from ..util import as_json

if typing.TYPE_CHECKING:
from typing import Any
from typing import List
from typing import Optional
from typing import Tuple
Expand Down Expand Up @@ -45,6 +47,16 @@ def init_db(app: Sphinx, config: Config):
app.esbonio.db.ensure_table(CONFIG_TABLE)


def value_to_db(name: str, item: Any) -> Tuple[str, str, Any]:
"""Convert a single value to its DB representation"""

try:
(value, scope, _) = item
return (name, scope, as_json(value))
except Exception:
return (name, "", as_json(item))


def dump_config(app: Sphinx, *args):
"""Dump the user's config into the db so that the parent language server can inspect
it."""
Expand All @@ -61,20 +73,18 @@ def dump_config(app: Sphinx, *args):
continue

try:
(value, scope, _) = item
values.append((name, scope, as_json(value)))
except Exception:
values.append((name, "", as_json(item)))
values.append(value_to_db(name, item))
except Exception as exc:
logger.debug(f"Unable to dump config value: {name!r}: {exc}")

for name, item in config.items():
if name in IGNORED_CONFIG_NAMES:
continue

try:
(value, scope, _) = item
values.append((name, scope, as_json(value)))
except Exception:
values.append((name, "", as_json(item)))
values.append(value_to_db(name, item))
except Exception as exc:
logger.debug(f"Unable to dump config value: {name!r}: {exc}")

app.esbonio.db.insert_values(CONFIG_TABLE, values)

Expand Down
4 changes: 4 additions & 0 deletions lib/esbonio/tests/workspaces/demo/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "env", ".tox", "README.md"]

linkcheck_allowed_redirects = {
# All HTTP redirections from the source URI to the canonical URI will be treated as "working".
r"https://sphinx-doc\.org/.*": r"https://sphinx-doc\.org/en/master/.*"
}

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
Expand Down

0 comments on commit 02649e9

Please sign in to comment.