Refactor line search error checking code. Move the error checking code into its own function so that it can be used in upcoming changes. Change-Id: Icf348e5a8bbe8f8b663f04fb8cfc9a2149b12f22