Added error handling for directive.