Your error message seems unrelated to the code you’ve posted. Please consider proving a MWE as outlined here.