Sorry, but seriously, I've been trying to work on this, as well. I don't know your exact situation, but I've found a lot of this comes down to being able to have the confidence to tell your boss "No, I don't think I should be working on that, for X, Y, Z reasons."
There are shit bosses out there, who will still blame you if they put you in a bad situation and it goes bad, but the best you can do is be upfront that you do not believe this situation is set up for success and how it could be improved.
Sorry, but seriously, I've been trying to work on this, as well. I don't know your exact situation, but I've found a lot of this comes down to being able to have the confidence to tell your boss "No, I don't think I should be working on that, for X, Y, Z reasons."
There are shit bosses out there, who will still blame you if they put you in a bad situation and it goes bad, but the best you can do is be upfront that you do not believe this situation is set up for success and how it could be improved.