I concur with Michael that it's inappropriate to make an end run around _dosmaperr() here. If you think that the DEBUG5 logging inside that is inappropriate, you should propose removing it outright.
Pushed the rest of this.
Great, thanks again to everyone who has taken some time to look into this.