Cannot read property '0' of undefined when editing user

Description

Hello, Rocket team!
We are migrating from Slack to Rocket Chat. We have deployed clean standalone Rocket Chat, then we have imported Slack users archive with Import → Import New File → Slack + Upload → select archive → Import → confirm importing all the users.
But now we are getting error “Cannot read property ‘0’ of undefined”, when saving changes in any user editing window.

Mentioned Slack archive, that we have imported: all user without confidentional.zip - Google Drive
Can you try to reproduce our issue with that archive?

Server Setup Information

  • Version of Rocket.Chat Server: 4.5.0
  • Operating System: CentOS Linux release 7.9.2009 (Core)
  • Deployment Method: deployment method How to Install Rocket.Chat on CentOS 7 - Vultr.com (yum + src)
  • Number of Running Instances: 1
  • DB Replicaset Oplog:
  • NodeJS Version: v14.0.0
  • MongoDB Version: 4.2.19 / wiredTiger (oplog Enabled)
  • Proxy: nginx/1.20.1
  • Firewalls involved: iptables, ACCEPT ALL

Any additional Information

The error accompanied by these logs:
{“level”:20,“time”:“2022-03-17T07:36:34.213Z”,“pid”:14031,“hostname”:“dub-srv-rc-test”,“name”:"",“name”:“Callbacks”,“msg”:“Executing callback with id check-max-user-seats for hook validateUserRoles”}
{“level”:35,“time”:“2022-03-17T07:36:34.219Z”,“pid”:14031,“hostname”:“dub-srv-rc-test”,“name”:"",“name”:“API”,“method”:“POST”,“url”:"/api/v1/users.update",“userId”:“uCjT9Zou3skJTx4bG”,“userAgent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0”,“length”:“288”,“host”:“10.10.4.125:3000”,“referer”:“http://10.10.4.125:3000/admin/users/edit/LKdL3P5NmvzXNt8jL",“remoteIP”:“192.168.10.116”,“err”:{“type”:“TypeError”,“message”:"Cannot read property ‘0’ of undefined”,“stack”:“TypeError: Cannot read property ‘0’ of undefined
at validateUserEditing (app/lib/server/functions/saveUser.js:210:3)
at saveUser (app/lib/server/functions/saveUser.js:344:2)
at DDPCommon.MethodInvocation. (app/api/server/v1/users.js:594:40)
at packages/dispatch_run-as-user.js:211:14
at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1257:12)
at Object.Meteor.runAsUser (packages/dispatch_run-as-user.js:210:33)
at Object.post (app/api/server/v1/users.js:594:11)
at app/api/server/api.js:425:96
at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1257:12)
at Object._internalRouteActionHandler [as action] (app/api/server/api.js:425:39)
at Route._callEndpoint (packages/rocketchat_restivus/lib/route.coffee:150:32)
at packages/rocketchat_restivus/lib/route.coffee:59:33
at packages/simple_json-routes.js:100:9”},“status”:400,“responseTime”:15,“msg”:“Cannot read property ‘0’ of undefined”}

Hi!

This usually happens when the user doesn’t have an email.

We have a recently merged PR for that:

wow! that’s great, thank you! But can you clarify, in which version of Rocket Chat this PR will be included?

@dudanogueira We tested on Rocket Chat version 4.5.2. The error still persist. So that PR have not included in 4.5.2?

It was not. It may be included on the next release.

Can you check if the imported user has an email? Also, can you check if you go to mongo directly and add the attribute email (even without any email) will sove this?

This fix should avoid breaking the save process to go thru, but it would be nice to add the email attribute to slack import, even when there is no email defined.

  1. Checked. Imported users have no email in Rocket data base. Plus we investigated Slack admin settings and found out, that we can include email field into the export by setting email as public parameter: go to https://our_domain.slack.com/admin/settings#display_email_addresses → Email Display → Members and guests of <our_domain>, plus people from organizations you’re connected to → request new export, now your backup will contain users.json file, which includes emails field.

  2. We are not experts in managing Mongo, so can you provide us an example of the request command for adding the email attribute to the user?

1 Like
  1. nevermind. We have successfully done adding email to user directly via Mongo as you suggested. Test is passed - now that user can be edited without error.

Please consider using latest (as of now 4.5.2) as the fix is coming soon.