HKUDS/DeepTutor · error · ValueError

Invalid book_id: {book_id!r}

Error message

Invalid book_id: {book_id!r}

What it means

Error "Invalid book_id: {book_id!r}" thrown in HKUDS/DeepTutor.

Source

Thrown at deeptutor/learning/storage.py:270

        self._root = root or (get_path_service().get_workspace_dir() / "learning")
        self._root.mkdir(parents=True, exist_ok=True)
        self._initialized = False
        self._ensure_initialized()

    @property
    def db_path(self) -> Path:
        return Path(self._root) / self._DB_FILENAME

    def _path(self, book_id: str) -> Path:
        """Return the legacy JSON location after validating the public id."""
        self._validate_id(book_id)
        return Path(self._root) / f"{book_id}.json"

    @staticmethod
    def _validate_id(book_id: str) -> str:
        value = str(book_id or "")
        if not value or "/" in value or "\\" in value or ".." in value or ":" in value:
            raise ValueError(f"Invalid book_id: {book_id!r}")
        return value

    def _ensure_initialized(self) -> None:
        db_path = self.db_path.resolve()
        if self.db_path.exists() and (
            getattr(self, "_initialized", False) or db_path in _initialized_db_paths
        ):
            self._initialized = True
            return
        with _schema_lock:
            if self.db_path.exists() and db_path in _initialized_db_paths:
                self._initialized = True
                return
            Path(self._root).mkdir(parents=True, exist_ok=True)
            with self._connect(initialize=False) as conn:
                conn.executescript(
                    """
                    PRAGMA journal_mode = WAL;

View on GitHub (pinned to 3e82f13042)

When it happens

Trigger: Thrown at deeptutor/learning/storage.py:270 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/f2a873f97b0604b5. Report an issue: GitHub.