can1357/oh-my-pi · error · ValueError
scheme must be a non-empty string
Error message
scheme must be a non-empty string
What it means
host_uri() registers a custom URI scheme (e.g. 'omp://...') with the host, and it refuses to register a scheme that is empty or whitespace-only. The scheme is cleaned via `(scheme or '').strip().lower()` before validation, so None, empty strings, and strings of only spaces all fail. This is an upfront programmer-error guard so registrations with typos or unpopulated variables fail loudly instead of producing unusable URIs.
Source
Thrown at python/omp-rpc/src/omp_rpc/host_uris.py:85
description: str | None = None
immutable: bool = False
@property
def writable(self) -> bool:
return self.write is not None
def host_uri(
*,
scheme: str,
read: HostUriReadHandler,
write: HostUriWriteHandler | None = None,
description: str | None = None,
immutable: bool = False,
) -> HostUri[None]:
cleaned = (scheme or "").strip().lower()
if not cleaned:
raise ValueError("scheme must be a non-empty string")
return HostUri(
scheme=cleaned,
read=read,
write=write,
description=description,
immutable=immutable,
)
def normalize_read_result(value: HostUriReadValue) -> JsonObject:
"""Convert a handler's `read` return into the wire-frame fields.
Returns a dict suitable for spreading into a `host_uri_result` payload.
"""
if isinstance(value, str):
return {"content": value}
if not isinstance(value, dict):View on GitHub (pinned to 9690622007)
Solutions
- Pass a non-empty literal scheme string, e.g. host_uri('mydata') (no '://' suffix; the function lowercases and strips it for you)
- Check the config/env source that supplied the scheme and give it a real value or a non-empty default
- Add a caller-side check: if not scheme or not scheme.strip(): raise/skip the registration
Example fix
// before
scheme = os.environ.get('OMP_SCHEME', '')
h = host_uri(scheme, read=read_handler)
// after
scheme = os.environ.get('OMP_SCHEME') or 'mydata'
h = host_uri(scheme, read=read_handler) Defensive patterns
Strategy: validation
Validate before calling
def validate_scheme(scheme):
if not isinstance(scheme, str) or not scheme.strip():
raise ValueError(f"scheme must be a non-empty string, got {scheme!r}")
return scheme Type guard
def is_valid_scheme(scheme) -> bool:
return isinstance(scheme, str) and bool(scheme.strip()) Try / catch
try:
h = host_uri(scheme, read=read_handler)
except ValueError as e:
logger.error('host_uri registration failed: %s (scheme=%r)', e, scheme)
raise Prevention
- Never default scheme to '' — use None and fail explicitly, or a real default
- Strip and lowercase at the config-loading layer so bad values are caught early
- Add a startup assertion/test that all registered schemes are non-empty
When it happens
Trigger: Calling host_uri('') or host_uri(None), passing a scheme read from an unset config/env variable that resolves to an empty string, or a scheme variable populated via a lookup that returned '' (e.g. dict.get('scheme') missing). Note whitespace-only strings like ' ' also trigger it after stripping.
Common situations: Config files with `scheme:` left blank, env vars like OMP_URI_SCHEME unset and defaulted to '', f-string/format placeholders that stayed empty, or a refactoring that split the scheme out of a full URI string but produced an empty prefix.
Related errors
- Unsupported content_type: {content_type!r}
- Failed to load tree-sitter language: {err}
- Host URI scheme must be a non-empty string
- Host URI scheme contains invalid characters: ${raw.scheme}
- Host URI scheme is reserved by OMP: ${scheme}://
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/95ffb49d99f026a8.
Report an issue: GitHub.