"""
scrapple.utils.exceptions
~~~~~~~~~~~~~~~~~~~~~~~~~

Functions related to handling exceptions in the input arguments
"""

import re

class InvalidType(ValueError):
	"""Exception class for invalid type in arguments."""
	pass


class InvalidSelector(ValueError):
	"""Exception class for invalid in arguments."""
	pass


class InvalidOutputType(ValueError):
	"""Exception class for invalid output_type in arguments."""
	pass


class InvalidProjectName(ValueError):
	"""Exception class for invalid <projectname> in arguments."""
	pass



def check_arguments(args):
	"""
	Validates the arguments passed through the CLI commands.

	:param args: The arguments passed in the CLI, parsed by the docopt module
	:return: None

	"""
	projectname_re = re.compile(r'[^a-zA-Z0-9_]')
	if args['genconfig']:
		if args['--type'] not in ['scraper', 'crawler']:
			raise InvalidType("--type has to be 'scraper' or 'crawler'")
		if args['--selector'] not in ['xpath', 'css']:
			raise InvalidSelector("--selector has to be 'xpath' or 'css'")
	if args['generate'] or args['run']:
		if args['--output_type'] not in ['json', 'csv']:
			raise InvalidOutputType("--output_type has to be 'json' or 'csv'")
	if args['genconfig'] or args['generate'] or args['run']:
		if projectname_re.search(args['<projectname>']) is not None:
	if int(args['--levels']) < 1:
		raise Exception("--levels should be greater than, or equal to 1")
	return
			message = "<projectname> should consist of letters, digits or _"
			raise InvalidProjectName(message)

@@ -530,16 +530,112 @@
 %09pass%0A%0A%0A
+class InvalidLevels(ValueError):%0A%09%22%22%22Exception class for invalid levels in arguments.%22%22%22%0A%09pass%0A%0A
 %0Adef che
@@ -1393,16 +1393,128 @@
 t None:%0A
+%09%09%09message = %22%3Cprojectname%3E should consist of letters, digits or _%22%0A%09%09%09raise InvalidProjectName(message)%0A%09try:%0A%09
 %09if int(
@@ -1542,24 +1542,19 @@
 :%0A%09%09
-raise Exception(
+%09message = 
 %22--l
@@ -1601,87 +1601,193 @@
 o 1%22
-)%0A%09return%0A%09%09%09message = %22%3Cprojectname%3E should consist of letters, digits or _%22%0A%09
+%0A%09%09%09raise InvalidLevels(message)%0A%09except (TypeError, ValueError):%0A%09%09message = %22 %22.join(%5B%0A%09%09%09%22--levels should be an integer and not of type%22,%0A%09%09%09%22%7B%7D%22.format(type(args%5B'--levels'%5D))%0A%09%09%5D)%0A
 %09%09ra
@@ -1793,33 +1793,28 @@
 aise Invalid
-ProjectName
+Levels
 (message)%0A

Add custom error class 'InvalidLevels'