lib: fix error handling