improved errors handling

Signed-off-by: Luca Lianas <lucalianas@gmail.com>