Reports indicate Iranian officials informed the Iraqi government before the attack & the Iraqis informed U.S. officials.
Conclusion:
This attack was for Tehran to save face.
-Report claims U.S. B-52s based in Qatar & UAE being armed & fueled
-Khamenei boasts of ‘slap in the face’ against US
-Tehran threatens to attack UAE, Israel
-Iran's Def Min: Our next step will depend on US actions
-Iraq PM: Iran messaged us before the attack
"Aftermath of Iranian missile that landed near my hometown of Bardarash district in Duhok province, 80 kilometers from Erbil. No military site is even close to the area."