If the error is a 'but-for' cause of death, then I think it ought to be counted. All treatments are aimed at addressing an underlying problem. Just because that problem is terminal doesn't change the fact that a mistake killed the patient. As someone who just watched up close a loved one die from cancer over a seven-year period, you really come to appreciate every minute that they're still breathing (with some allowance for the final, vegetative stages).
The argument against counting it is that extremely risky surgeries are generally only performed when the patient is going to die otherwise. Those risky surgeries have a much higher rate of mistakes, but that's generally deemed acceptable, as long as that risk is properly communicated to the patient's family.
The doctors most commonly sued for malpractice are those doctors with poor communication skills rather than the doctors who make the most mistakes.
Any process with people is going to have mistakes.
At the end of the day we have to accept that the errors will be there, no matter what you or doctors do, period.
And as in all other industries where errors have a high impact, you have to design your process / systems / procedures so that you get an acceptable result even if people make mistakes, and it takes a combination of multiple errors (or an error combined also with negligence) to kill someone.