It can not work for user roles that don’t see and don’t have access to the menu section. It just is not there – for them -, so you can’t address it, hence the errors you are getting. Just add a check:
if( current_user_can( 'edit_posts' ) ) {
//code
}