On macOS 10.12.6 SIP was disabled (to issue an NVRAM command).
Unrelated to that command, but very possibly related to disabled SIP: After a reboot the Spotlight icon is gone, the PreferencePane errors with "Could not load Spotlight preference pane" and the Spotlight process crashes constantly.
Launchd reports com.apple.spotlight as status 6971 (the numbers vary) at first and then SIGABRT; and the crash reporter lists:
Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Application Specific Information: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString count]: unrecognized selector sent to instance 0x7fffa84e4d40' terminating with uncaught exception of type NSException abort() called
I then tried disabling Spotlight with
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
That executed without an error message.
sudo mdutil -a -i off
also ran without error before disabling Spotlight. Now the error message for that command is:
Spotlight server is disabled.
The ActivityMonitor now only lists SpotlightAggregator as still running, no "Spotlight" no "md*" process appears.
EtreCheck highlights this info:
System Software: macOS Sierra 10.12.6 (16G1408) System Load: 2.43 (1 min ago) 2.25 (5 min ago) 1.83 (15 min ago) Diagnostics Information (past 7 days): Spotlight.app Crash /System/Library/CoreServices/Spotlight.app *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString count]: unrecognized selector sent to instance 0x7fffa90ced40' terminating with uncaught exception of type NSException abort() called
The Activity Monitor offering "Spotlight Diagnostics" produces a lot of data, but does not reveal anything apparent.
sudo launchctl list | grep -i md - 0 com.apple.metadata.mds.scan - 0 com.apple.mtmd - 0 com.apple.mdmclient.daemon 228 0 com.apple.mDNSResponderHelper.reloaded - 0 com.apple.metadata.mds.index - 0 com.apple.msrpc.mdssvc 222 0 com.apple.mDNSResponder.reloaded 2428 0 com.apple.xpc.smd 80 0 com.apple.metadata.mds - 0 com.apple.platform.ptmd - 0 com.apple.metadata.mds.spindump 79 0 com.apple.warmd
The ReportCrash process now hovers on this machine between 40% and 100% CPU utilisation, as Spotlight crashes 6 times a minute..
It would be nice to get to the bottom of the cause of this but despite never using Spotlight a quick fix for the crashes would be nice to have.
How do I fix this error? At least how do I stop Spotlight from disabling the whole computer with its constant crash reports?
Update: Created an installation medium and re-installed with the latest Sierra installer over the old System. System is now downgraded to 10.12.6 (16G29).
Result: Spotlight still crashes.
After another clean install
Update2: After a clean install Spotlight worked as advertised. But the most stupid idea ever that is MigrationAssistant did migrate the error as well. I conclude that the error is not in the binaries that Apple ships out but within a configuration file that MigrationAssistant does not sanitise.
After another clean install of the system I have to observe Spotlight crashing along with AppleSpell, suggestd, CalendarAgant, and SafarBookamrksSyncAgent. On my migrated admin user. (Copied manually just that user's folder).
These symptoms do not appear with another admin user.