Change API to make error handling more consistent

Signed-off-by: Ondrej Kupka <ondra.cap@gmail.com>