When installing any optional features, if the installation fails in between, it's primarily because of internet issues. Some features are downloaded from the Microsoft server, so a stable network connection is necessary. However, if this happens for a feature that doesn't need a connection, you should run the DISM, and SFC commands to fix any corruption in the system files.