Integrate error-handling changes from master into sparkplug-2.x.