[ILibrary / LazyLibrary] raise a LibraryError instead of KeyError

This commit is contained in:
Jan Petykiewicz 2026-04-01 22:58:30 -07:00
commit ce7bf5ce70
2 changed files with 13 additions and 0 deletions

View file

@ -826,6 +826,8 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
Returns:
self
"""
if old_name not in self:
raise LibraryError(f'"{old_name}" does not exist in the library.')
self[new_name] = self[old_name]
del self[old_name]
if move_references:
@ -1479,6 +1481,8 @@ class LazyLibrary(ILibrary):
Returns:
self
"""
if old_name not in self.mapping:
raise LibraryError(f'"{old_name}" does not exist in the library.')
self[new_name] = self.mapping[old_name] # copy over function
if old_name in self.cache:
self.cache[new_name] = self.cache[old_name]