RPC call sendtoaddress doesn't check for available funds before the call to SendMoney. This results in suboptimal RPC error code returned. RPC_WALLET_ERROR (-4) instead of RPC_WALLET_INSUFFICIENT_FUNDS (-6):
# Before:
pavel$ ./bitcoin-cli sendtoaddress m...address... 1000
error: {"code":-4,"message":"Insufficient funds"}
# After:
pavel$ ./bitcoin-cli sendtoaddress m...address... 1000
error: {"code":-6,"message":"Insufficient funds"}
This fixes issue #3007.