Custom grains directories
Handle better state errors

This fixes #9983.
Merge branch 'graindirs' into develop
Merge branch 'handleerror' into develop