I tested your code and do not have any issues with OnBarUpdate errors.
You will need to use Try-Catch blocks to isolate the segment in your code which is throwing the error as we would not be able to debug this for you.
More information on using Try-Catch blocks can be found below:
Comment