One thing that you can, do is mark on the side of the drum the position of the weights its a bit rough, but should show any major movement, try to recreate the error, if they have moved then as others have said cleaning can help, but if they have not moved, you need to look at other things. Rather the markings you can use the balancer test to find the current position before and after the error as an alternative, this is more accurate
The error does very much have to do with flag and sensors as the machine only knows where the balancer weights are on the drum via the flag and sensor. If the weights have moved when they should not, it is known via the flag and sensor. Equally if the sensor can not see the flag when it spins at high speed you can get errors. Sometimes the sensors are OK at normal load time / balancer change time, but during high speed drum rotation can error, it is less common, but can happen if sensors are just on the borderline of reading the flag