Do you lose a turn/spell slot when casting a spell on invalid creatures?

Say my Mystic attempts to cast Fear as a 1st level spell on a creature.

1st: When you cast fear as a 1st-level spell, it affects one living creature of CR 4 or lower at close range…

If the DM reveals that the creature is above CR 4 and would be unaffected, does my turn then end with one of my 1st level spell slots being consumed?

As far as I could tell, I couldn’t find any specific rules about this in the spellcasting section of the CRB or elsewhere. I also haven’t played Pathfinder, but this question might apply for that system as well.