Reject ambiguous library names and empty library-set entries (#33)

* Reject ambiguous library names and empty library-set entries

get_library_id() silently picked the first library matching a
requested name, so two libraries sharing a name would sync whichever
happened to come first in the server's response - not necessarily the
one the operator meant. It now raises ConfigError when a name matches
more than one library.

resolve_libraries() rejects an empty entry produced by an empty
LIBRARY_ID, 'a::b', or a leading/trailing ':' the same way, instead of
silently logging 'library  not found' and moving on.

* Clarify get_library_id's ambiguity docstring and error message

Copilot review: the input can be a name or an ID, and the error said
'Library name' even for an ID collision; use neutral wording. Also
made the docstring's second sentence a complete one.

---------

Co-authored-by: Maxim Shulga <maxim.shulga@alludo.com>
This commit is contained in:
Maksim ShulgaandMaxim Shulga authored and GitHub committed 2026-08-03 18:38:06 +00:00
1 parent 6f8af2cfa4
commit ba5ad177b7
4 files changed
+86 -6

No files matched your search

+7 -1
View File
@@ -53,8 +53,14 @@ def defaults_from_env() -> dict:
def resolve_libraries(client, requested: str, server: str) -> set:
"""Map the requested names or IDs to library IDs that are not synced yet."""
requested_names = requested.split(sep=":")
if any(name == "" for name in requested_names):
raise ConfigError(
f"library set must not contain an empty entry, got {requested!r}"
)
libs_to_sync = set()
for arg_lib in requested.split(sep=":"):
for arg_lib in requested_names:
lib_id = client.get_library_id(arg_lib)
if lib_id:
libs_to_sync.add(lib_id)