It seems to me that this is a particularly common and undesirable problem when cooking curries. I therefore thought it might be helpful to summarise a few of the common causes of bitterness (in my opinion) as follows:
- onions that have not been cooked slowly enough or for long enough (i.e. to remove the "rawness" and develop "sweetness")
- onions that have been pureed (rather than coarsely chopped) before cooking
- onions that have been fried rather than boiled
- spices that have not been cooked adequately (to remove the "rawness")
- burning the spices (including when roasting them)
- burning anything else!
- using too much of a particular spice (e.g. tumeric, fenugreek seeds/powder, etc)
- using tinned tomatoes, which I find can be quite acidic (consider using puree, paste or fresh)
Some people disagree with the last point, but it is certainly what I have found.
There has also been some mention of aluminium pans also causing bitterness.
Of course, some curries are intended to be sour (e.g. Vindaloo) and the desired sourness is achieved by adding things like tamarind, lemon juice, vinegar, yoghurt, etc
Here are some other relevant threads that might be of interest:
https://curry-recipes.co.uk/curry/index.php?topic=1095.0https://curry-recipes.co.uk/curry/index.php?topic=627.0To counteract slight bitterness, try adding some sugar (or other sweetners such as tomato sauce, mango chutney, pineapple juice, etc)
Please feel free to add to this thread with your own observations and opinions!

Hope this helps!