Make sure requested pattern is valid

As a security precaution, this checks that the requested generator is valid before attempting to call it.

/cc @gjtorikian @gregose @andrew