main: check for return codes

If functions return an error, exit the program.