Write img fail when flashing a patched boot.img

Wait 5 sec.

When i flash a magisk patched boot.img to my phone, it always says "Write img fail". it does flash in fastbootd, but it ends up bootlooping, How do i fix this?