Multiple validation errors. Why?

  • I have a core data application. One entity is "Hit". This entity typically has no instances when the application starts, and gets populated during the execution of the program. All of the instances appear to be OK when viewed in a TableView. Some or all instances may get deleted before the application quits. If any instances remain when the app quits, I get a "multiple validation errors occured" message. The console has no error messages. In debugging, I have gone so far as supplying no data at all when adding any instances, so they get created with default values only. Still I get the error message. Some attributes are strings, some are 16 bit integers, and some are 32 bit integers. The string defaults are empty strings, and the integer defaults are zero. I am creating Hit instances with this method

    NSManagedObject *newHit = [NSEntityDescription
                                    insertNewObjectForEntityForName:@"Hit"
                                    inManagedObjectContext:[appDelegate managedObjectContext]];

    The app has three other entities, but they don't cause validation errors. Can anyone help?

    Lynn Barton
  • > I have a core data application. One entity is "Hit". This entity typically has no instances when the application starts, and gets populated during the execution of the program. All of the instances appear to be OK when viewed in a TableView. Some or all instances may get deleted before the application quits. If any instances remain when the app quits, I get a "multiple validation errors occured" message. The console has no error messages. In debugging, I have gone so far as supplying no data at all when adding any instances, so they get created with default values only. Still I get the error message. Some attributes are strings, some are 16 bit integers, and some are 32 bit integers. The string defaults are empty strings, and the integer defaults are zero. I am creating Hit instances with this method

    The NSError has an -userInfo dictionary with at least some answers to your questions in it.

    - Ben
  • On Wed, 17 Mar 2010 21:05:06 -0700, Lynn Barton said:

    > the app quits, I get a "multiple validation errors occured" message. The
    > console has no error messages.

    Stick this in your app delegate:

    - (NSError*)application:(NSApplication*)application
      willPresentError:(NSError*)error
    {
    if (error)
    {
      NSDictionary* userInfo = [error userInfo];
      NSLog (@"encountered the following error: %@", userInfo);
      Debugger();
    }

    return error;
    }

    --
    ____________________________________________________________
    Sean McBride, B. Eng                <sean...>
    Rogue Research                        www.rogue-research.com
    Mac Software Developer              Montréal, Québec, Canada
  • On Mar 18, 2010, at 7:51 AM, Sean McBride wrote:

    > On Wed, 17 Mar 2010 21:05:06 -0700, Lynn Barton said:
    >
    >> the app quits, I get a "multiple validation errors occured" message. The
    >> console has no error messages.
    >
    > Stick this in your app delegate:
    >
    > - (NSError*)application:(NSApplication*)application
    > willPresentError:(NSError*)error
    > {
    > if (error)
    > {
    > NSDictionary* userInfo = [error userInfo];
    > NSLog (@"encountered the following error: %@", userInfo);
    > Debugger();
    > }
    >
    > return error;
    > }
    >
    > --
    > ____________________________________________________________
    > Sean McBride, B. Eng                <sean...>
    > Rogue Research                        www.rogue-research.com
    > Mac Software Developer              Montréal, Québec, Canada
    >

    Thanks. That was just the help I needed. Console messages showed that I needed to explicitly set the value of one of the string attributes, which was defined with a minimum length of zero and a blank default value. Once I programmatically set the value to @"" the errors went away. Things are looking up.

    Lynn Barton
  • On 2010 Mar 18, at 21:04, Lynn Barton wrote:

    > That was just the help I needed. Console messages showed that I needed to explicitly set the value of one of the string attributes, which was defined with a minimum length of zero

    After I had something like this happen a couple times, I decided to *never* set those minimum and maximum values, and always leave the 'Optional' boxes checked in a Core Data model.  Inevitably, often just momentarily as things are being created or torn down, there will be an illegal value.  If I need validation, I do it in my own code and take appropriate action.  Most users don't react well to a boldfaced "Multiple validation errors occurred."

    Also, Sean's code illustrates another reason to use your own error presentation -- Cocoa's sometimes loses helpful information.  You may not want to display it all to the user, but you can at least log it.  My alert has an 'Email Support' button which, when clicked, writes a nicely formatted -longDescription of the error to the body of an email message.
previous month march 2010 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today