Blessing in disguise
A blessing in disguise is an English language idiom referring to the idea that something that appears to be a misfortune can have unexpected benefits. It first appeared in James Hervey's hymn "Since all the downward tracts of time" in 1746, and is in current use in everyday speech and as the title of creative works such as novels, songs and poetry.

Origins
The phrase originated in the hymn "Since all the downward tracts of time" by James Hervey (1714–1758), first published in "Reflections on a Flower-garden. In a letter to a lady" (1746), a volume in his best known work, Meditations and Contemplations (1746–1747), but composed earlier. In the hymn, Hervey meditated on the wisdom of accepting whatever God, in his infinite wisdom, chose to bestow on us, even things that appeared at first to be negative, because they were "blessings in disguise":

Since all the downward tracts of time
God's watchful eye surveys,
O who so wise to choose our lot
Or to appoint our ways?

Good when He gives, supremely good,
Nor less when He denies;
Ev'n crosses from His sovereign hand
Are blessings in disguise.

Why should we doubt a Father's love,
So constant and so kind?
To His unerring, gracious will
Be every wish resigned.

The draft manuscript of "Reflections on a Flower-garden", along with other works by Hervey, is held by the University of Leeds Special Collections.

Usage
The phrase has been used in a variety of mediums. In 1865, a cartoon titled "Blessings in Disguise" from the American Civil War era showed Confederate states president Jefferson Davis surrounded by cities in which the Confederates had been defeated, asking whether the losses were a "blessing in disguise" that prevented the Confederate Army being stretched too thinly. A Chinese folk tale tells of how an injury saved a man's life by preventing him from being killed in battle. The phrase is expressed in the words An Zhi Fei Fu. In 1900, The British Medical Journal commented on a number of cases where an assault or injury inadvertently led to the curing of a medical condition, describing them as surgical blessings in disguise.
 
In the modern era, the phrase has been used as the title of multiple books, such as the novel of that name by Danielle Steel (2019), songs by Michael McDonald, Michael Martin Murphy and others, and as the name of a charity.

Related phrases
Related phrases are "count your blessings", meaning to be grateful for the good things that have happened to you and not spending time regretting the bad, and a "mixed blessing", meaning something that has good and bad aspects.