Have command error handling take `impl FnOnce` instead of a function pointer (#24831)