set ecode before trying to print it to stderr

Signed-off-by: Peter Palfrader <peter@palfrader.org>