{"record":{"id":"8a839b89f302580d","repo":"laurent22/joplin","slug":"should-include-in-email-address-email-user-email","errorCode":null,"errorMessage":"Should include @ in email address, email: ${user.email}","messagePattern":"Should include @ in email address, email: (.+?)","errorType":"validation","errorClass":"ErrorUnprocessableEntity","httpStatus":422,"severity":"error","filePath":"packages/server/src/models/UserModel.ts","lineNumber":469,"sourceCode":"\t\t\tif (result.feedback.suggestions) {\n\t\t\t\tmsg = msg.concat(result.feedback.suggestions);\n\t\t\t}\n\t\t\tthrow new ErrorUnprocessableEntity(msg.join(' '));\n\t\t}\n\t}\n\n\tprotected async validate(object: User, options: ValidateOptions = {}): Promise<User> {\n\t\tconst user: User = await super.validate(object, options);\n\n\t\t// Note that we don't validate the password here because it's already\n\t\t// been hashed by then.\n\t\tif (options.isNew) {\n\t\t\tif (!user.email) throw new ErrorUnprocessableEntity('email must be set');\n\t\t\tif ('email' in user && !user.email.includes('@')) throw new ErrorUnprocessableEntity(`Should include @ in email address, email: ${user.email}`);\n\t\t\tif (!user.password && !user.must_set_password) throw new ErrorUnprocessableEntity('password must be set');\n\t\t} else {\n\t\t\tif ('email' in user && !user.email) throw new ErrorUnprocessableEntity('email must be set');\n\t\t\tif (user.email && !user.email.includes('@')) throw new ErrorUnprocessableEntity(`Should include @ in email address, email: ${user.email}`);\n\t\t\tif ('password' in user && !user.password) throw new ErrorUnprocessableEntity('password must be set');\n\t\t}\n\n\t\tif (user.email) {\n\t\t\tconst existingUser = await this.loadByEmail(user.email);\n\t\t\tif (existingUser && existingUser.id !== user.id) throw new ErrorUnprocessableEntity(`there is already a user with this email: ${user.email}`);\n\t\t\t// See https://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690 (found via https://stackoverflow.com/a/574698)\n\t\t\tif (user.email.length > 254) throw new ErrorUnprocessableEntity('Please enter an email address between 0 and 254 characters');\n\t\t\tvalidateEmail(user.email);\n\t\t}\n\n\t\tif (user.full_name && user.full_name.length > 256) throw new ErrorUnprocessableEntity('Full name must be at most 256 characters');\n\n\t\treturn super.validate(user, options);\n\t}\n\n\t// public async delete(id: string): Promise<void> {\n\t// \tconst shares = await this.models().share().sharesByUser(id);","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/laurent22/joplin/blob/981a03c5c9e88130bccff4db47c411d35ec7ae2c/packages/server/src/models/UserModel.ts#L451-L487","documentation":"UserModel.validate throws ErrorUnprocessableEntity('Should include @ in email address') when the provided email string does not contain an '@'. This is a cheap sanity check applied to both new users and updates before the more thorough validateEmail() RFC check runs later.","triggerScenarios":"Saving or updating a user whose email value is a non-address string lacking '@', e.g. 'johndoe' or 'foo.bar'.","commonSituations":"Import scripts mapping the wrong CSV column into email; users typing a username instead of an email; API clients sending the display name as email.","solutions":["Send a properly formatted email address containing '@'.","Run client-side syntax validation (must contain '@') before submitting.","Trim whitespace — a stray space is still caught, so sanitize input first."],"exampleFix":"// before\nawait models.user().save({ email: 'johndoe', password: 'x' }, { isNew: true });\n// after\nconst email = 'john@example.com';\nif (!email.includes('@')) throw new Error('Invalid email');\nawait models.user().save({ email, password: 'x' }, { isNew: true });","handlingStrategy":"validation","validationCode":"if (email && !email.includes('@')) throw new Error('Invalid email format');","typeGuard":"function looksLikeEmail(s: string): boolean { return s.includes('@'); }","tryCatchPattern":"try { await models.user().save(user, opts); } catch (e) { if (/Should include @ in email/.test(e.message)) /* show format error */; }","preventionTips":["Use a proper email regex or input type=email on the client before calling the API.","Trim and normalize email input; map the correct source column in imports."],"tags":["server","validation","email-format"],"backgroundTag":"invalid-argument-format","analyzedSha":"981a03c5c9e88130bccff4db47c411d35ec7ae2c","analyzedAt":"2026-09-17T14:49:40.960Z","contentChangedAt":"2026-09-17T14:49:40.960Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}