apply: clean up error handling.
Sponsored by: Klara, Inc.
(cherry picked from commit 441202c00bdf6edbf6b6bc1b1923bebd8e2d8e45)