Add null guards and more error logging to force on-save handler.