Plugin to validate a text type custom field value

I know for sure that this piece of code is what causes the 500 Internal Server Error:

Is there anybody out there who can tell me how to get at the user field value of a custom field?

Other peices poeces of code that aren’t workijg either:

custom_field_value = self.user.reload.custom_fields[custom_field_key]
custom_field_value = UserCustomField.where(user_id: self.user.id, name: custom_field_key).pluck(:value).first

Any ideas / pointers to documentation pr code?