Return errors instead of crashing with log.

Signed-off-by: Douézan-Grard Guillaume <gdouezangrard@gmail.com>