[bugfix] Fix a bug in error handling

Repushing this as it is useful for error management done right ...