This is a case where a very good interface (letting you click on the card to gain directly and deducting the necessary coins automatically) can backfire in a rare case.
My suggestion: The game needs to figure out anyway which cards are gain-able with the available coins. Let it do the same with an assumed coin count of zero (that is, find out what the trashed card cost and find all the top supply cards with a lesser or equal cost). If the latter turns out empty, then present the user with an additional option "Don't spend coins and don't gain a card".
This way, the current intuitive interface is not changed in the overwhelming majority of cases, and edge cases like this can be handled with just a simple option.