Adds generic printError function in place of reuse of if statements