I think that the best starting point is to run sample with the option cores=1, that should make the errors source clearer.
The error seems to indicate that at some point in your code you try to use a variable called trace before it was given a value. A good reference about this error can be found here