Trying to get property of non-object

If you look at the documentation for get_term_by(), you’ll see that it:

Will return false if $taxonomy does not exist or $term was not found.

You need to account for this possibility in your code by checking the value of $term. You’ll also note from the documentation that get_term_by() does not return a WP_Error, so is_wp_error() is not useful. This is what you need:

$term = get_term_by( 'name', $name, $tax );

return $term ? $term->term_id : false;

The specific error you’re seeing is because if $term is false then $term->term_id is invalid code.