This question asks what happens when a single-target spell has an invalid target. (A target that is not legitimately permissible, not a target that is weak from illness or injury).
The answer to that question appears to be: that depends on whether one wishes to implement an older Sage Advice segment of a Dragon Talk podcast, or the more recent but optional written rules in Xanathar's Guide to Everything.
Assume for this question that I prefer XGtE.
The optional rule for resolving invalid spell targets states (XGtE, p. 85-86):
If you cast a spell on someone or something that can’t be affected by the spell, nothing happens to that target, but if you used a spell slot to cast the spell, the slot is still expended.
Now consider the chain lightning spell, whose description says:
You create a bolt of lightning that arcs toward a target of your choice that you can see within range. Three bolts then leap from that target to as many as three other targets, each of which must be within 30 feet of the first target. A target can be a creature or an object and can be targeted by only one of the bolts.
Suppose my primary target for the spell is invalid, because it is not a creature or an object. If an example must be given, suppose it is an illusion. However, each of the three secondary targets of the spell are valid, being either creatures or objects.
Do I spend the spell slot with nothing happening at all?
Or does the slot get spent as the chain lightning impacts the illusion but does nothing to it and then leaps to the three valid targets (with the full effects given in the spell description)?
Note: I am assuming that an illusion is not an object, based largely on my interpretation that an illusion is not an "item" and on the text of the 14th-level School of Illusion wizard feature, Illusory Reality.
I am open to frame challenges that demonstrate that illusions are, in fact, objects - but such answers will be better if they then either provide a more appropriate example of something that is not a creature or an object, or demonstrate that the question is moot since everything is at least either a creature or an object.