IDE uploads old sketch on compile error

My forum and gooogle searches, as well as digging around in the IDE folders on Windows 10 produced nothing useful, so I'll ask:

Is there's any way to configure or hack the Arduino IDE (v1.8.7) to keep it from uploading (and burning flash life cycles) when the compile associated with the upload button fails? I cannot imagine the wisdom of uploading the old binary when the newer code cannot compile. Can't the IDE see the exit code from avr-gcc?

I had guessed the IDE would use a '.bat' or '.cmd' file that could be tweaked, but the avr-gcc and avrdude invocations appear hardwired inside the IDE.

Other than abandoning arduino IDE, and/or resorting to some kind of MAKEFILE implementation, are there any other viable approaches for Windows (besides of course habitually always verifying before uploading)?

Thanks.

(deleted)

My IDE is definitely uploading (the old sketch) on compile failures.

What makes you think it's uploading the old sketch?

(deleted)

  1. open a new sketch
  2. put this line at the top of the sketch:
    bool doit=true;
  3. put this line in setup():
    Serial.begin(2000000); Serial.println("RESET");
  4. put this line in loop():
    if (doit)Serial.println(String("ert")+String(doit)); doit=false;
  5. select Tools->Serial Monitor
  6. click the 'upload' button
  7. observe the arduino board serial LED(s) blink during download
  8. observe that the Serial Monitor contains the expected:
    RESET
    ert1
  9. remove the trailing semi-colon from any one of the lines you added.

A) while watching the aruino board serial LED(s), click upload again
B) observe the LEDS blink quickly (thrice?) then a brief pause before blinking an addition time.

C) observe that the Serial Monitor first clears and then displays the same output as before.

D) note how this differs from pressing the onboard reset button in that the serial monitor does not clear.

… Because it was requested, below is the entire content of the IDE output window:

C:\Users\726ah\Documents\Arduino\IDE_BUG\IDE_BUG.ino: In function 'void loop()':

IDE_BUG:5:1: error: expected ';' before '}' token

}

^

exit status 1
expected ';' before '}' token

... To the inquiry about how the IDE would know the "old" download, I theorize that since the compile fails, the output from the prior 'ld' run is still laying around wherever it lives, suitable for [re]download.

For completeness, I have an OSEPP UNO R3 PLUS, not a genuine arduino board. The IDE may be seeing something on the serial interface that differs from arduino hardware.

(deleted)

I stand corrected.

I convinced myself that you are correct. Its not downloading, but the IDE is resetting the board such that the old sketch restarts. I changed my setup() to:

void setup() { delay(10000); Serial.begin(2000000); Serial.println("RESET"); }

to hold off the sketch's interaction with the serial port for ten seconds.

With that, the observables that accompany the failed compile is the serial LEDS do not blink until the sketch does its writes. However, the other onboard LED does blink at roughly the same time the serial monitor clears, the [old] sketch restarts, and the serial monitor displays my "RESET" ten seconds later, indicating the IDE was able to reset the board without me being able to see the serial LEDs do anything.

Thanks for challenging me to "think differently" so see things for what they really are.

(deleted)