I would start by putting ferrite beads on each wire coming from the programmer, right near the PCB connector side, maybe some ferrite glandules, too, or pass the cables through donnut ferrite cores, whatever available, as seen in the first 5 mins here
The idea is the high frequencies spikes will be reflected back by the ferrites, so the ferrite should be put at the noise source side of a cable. Some chokes on the motor wires might help, too, if possible.
Also decoupling caps on the power lines of the MCU, right near the MCU pins, are a must, but I'll assume the board already has proper decoupling. Beware of ground loops, too, the GND should be connected in only one point, preferably near the MCU GND pin.
Series resistors on the programming wires (or even in series with the motor wires if allowed) might help, too, but those are mostly to dampen the reflections and ringing, they won't stop much of the spikes getting into programmer.
You didn't said the error. If the error is on the USB side, and not in the programmer, and if the above measures does not solve the issue, then you might need a USB galvanic isolator.