Like what we’re doing? Star us on GitHub!

Best way to debug validation error encountered in admin?

ryanlanciaux
last year
2 1

I'm receiving a validation error for a non-existent field on a collection in the admin. My error states The following field is invalid: email. I don't have an email field on the collection. Updates work without issue / creating other collections seemingly works as well. Any advice on how to best go about debugging this?

Collection

const Locations: CollectionConfig = {
  slug: "locations",
  admin: {
    useAsTitle: "locationName",
  },
  fields: [
    {
      name: "locationName",
      type: "text",
    },
    {
      name: "address",
      type: "text",
    },
    {
      name: "address2",
      type: "text",
    },
    {
      name: "city",
      type: "text",
    },
    {
      name: "state",
      type: "text",
    },
    {
      name: "postalCode",
      label: "Zip code",
      type: "text",
    },
  ],
};

Stack Trace

[0] [17:25:36] ERROR (payload): ValidationError: The following field is invalid: email
[0]     at new ExtendableError (.../node_modules/payload/src/errors/APIError.ts:26:11)
[0]     at new APIError (.../node_modules/payload/src/errors/APIError.ts:43:5)
[0]     at new ValidationError (.../node_modules/payload/src/errors/ValidationError.ts:6:5)
[0]     at Payload.create (.../node_modules/payload/src/collections/operations/create.ts:209:11)
[0]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0]     at Payload.create (.../node_modules/payload/src/collections/requestHandlers/create.ts:14:17)
  • DanRibbens
    Payload Team
    last year

    Hey @ryanlanciaux I can't see anything wrong in what you've shared. Is it possible you had an email field previously and have not saved changes or restarted the server? Using yarn dev should pick up on changes as it uses nodemon, though I have seen instances where file changes are missed for some reason, stop it and restart if you haven't already.

    Here are some other thoughts:

    1. Do you have a mixup on your imports and the Locations you've shared is not what is being used?
    2. Is the POST request you're making to the api/locations route and not something else like api/users?
    3. What does the GraphQL type look like if you try going to http://localhost:3000/api/graphql-playground, expand the schema sidebar on the right and find locations. Does it really have an email field?
    4. You could inspect or console.log the app.config.collections from payload.init.onInit to see the schema. Does it have email?
    payload.init( {
    // [...]
    onInit: (app) => {
        console.log(app.collections.locations.Model.schema.tree);
        payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
      },
    });

    If the schema does not have it and yet the validation still expects email, I have no answer and will have to do some more digging.

    6 replies
  • DanRibbens
    Payload Team
    last year

    Hey @ryanlanciaux have you have had success with this or not? I would be happy to take a look at anything for your benefit if you are stuck in any way.

    LMK, cheers!

  • Ontopic
    last year

    I have no problems with email, but the original question is more I feel where to best access more detailed errors during validation. Now I personally write extra checks in decentralised places I have access to, but if something would be wrong with the email setting I wouldn't know where to start...

    SO, maybe I'm missing a doc (I see you guys secretly tweaking it), but a clear way to get more than error in collections[3][5] would be nice

  • jmikrut
    Payload Team
    last year

    Ahhhh @ryanlanciaux I bet you are having the same exact issue as was discussed here:

    #219

    @Ontopic — you're actually talking about startup config validation (I think) which is totally something that we need to improve. We are using Joi and there is definitely a way to make this better. That's on our radar to improve for sure.

  • ryanlanciaux
    last year

    Sorry I've been away from this for a bit and thanks so much for following-up. I'll confirm that this is what I'm bumping into and report back. 👍

  • DanRibbens
    Payload Team
    last year

    Okay! #237 adds the collection, global slugs and field names to the config validation errors.

  • ryanlanciaux
    last year

    @jmikrut Following up on this a bit late BUT #219 was exactly what I was encountering. Thanks a ton

Open the post
Continue the discussion in GitHub
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More