backporting @danielbachhuber's fix for an error notice