Error that was being logged: Core data error when a non-nil field is trying to be saved with a nil value
private static func logText(fromNSError error: NSError) -> String {
var log = error.debugDescription // Crashes here
return log
}
Note:
error.description also seems to crash
error.localizedDescription doesn't crash but doesn't have meaningful description of the actual error. It has a very generic error saying operation couldn't be completed.
Some background info:
In my app there are some errors that could be ignored, so I was trying to indent errors that could be ignored and encapsulate hard errors with "***"
Questions:
Am I missing something or is this a bug ?
Is there a better way to log with different levels of errors so that it can be differentiated visually on the console ?
Yes, you are correct, that code doesn't cause a crash.
I have a similar code which produces a core data error which causes the actual crash. The underlying error was caused when a core data entity non-nil field was saved with a nil value . It was a validation failure (constraint violation)
When I was trying to print the debug description of the error that's when it crashed.
Since it involves core data ... I was finding it difficult to express the code (as it involves entity and xcdatamodel etc).
I wanted to know if the pattern I was following was correct. The code shown is mocked up code to express the pattern I am following in my code.