improved error handling a bit

Signed-off-by: Marcin Wiatr <mail.wichura@gmail.com>