Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception base class already has message attribute, use that #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 30 additions & 71 deletions bin/q
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
# Its purpose is to bring SQL expressive power to manipulating text data using the Linux command line.
#
# Full Documentation and details in http://harelba.github.io/q/
# Full Documentation and details in http://harelba.github.io/q/
#
# Run with --help for command line details
#
Expand Down Expand Up @@ -237,98 +237,57 @@ class Sqlite3DB(object):
def drop_table(self, table_name):
return self.execute_and_fetch(self.generate_drop_table(table_name))

class CouldNotConvertStringToNumericValueException(Exception):

def __init__(self, msg):
self.msg = msg
class CouldNotConvertStringToNumericValueException(Exception):
pass

def __str(self):
return repr(self.msg)

class ColumnMaxLengthLimitExceededException(Exception):
pass

def __init__(self, msg):
self.msg = msg

def __str(self):
return repr(self.msg)

class MissingSqliteBckModuleException(Exception):

def __init__(self, msg):
self.msg = msg

def __str(self):
return repr(self.msg)
pass


class CouldNotParseInputException(Exception):
pass

def __init__(self, msg):
self.msg = msg

def __str(self):
return repr(self.msg)

class BadHeaderException(Exception):
pass

def __init__(self, msg):
self.msg = msg

def __str(self):
return repr(self.msg)

class EncodedQueryException(Exception):

def __init__(self, msg):
self.msg = msg

def __str(self):
return repr(self.msg)
pass


class CannotUnzipStdInException(Exception):
pass

def __init__(self):
pass

class UniversalNewlinesExistException(Exception):
pass

def __init__(self):
pass

class UnprovidedStdInException(Exception):
pass

def __init__(self):
pass

class EmptyDataException(Exception):
pass

def __init__(self):
pass

class MissingHeaderException(Exception):

def __init__(self,msg):
self.msg = msg
pass


class FileNotFoundException(Exception):

def __init__(self, msg):
self.msg = msg

def __str(self):
return repr(self.msg)
pass


class ColumnCountMismatchException(Exception):

def __init__(self, msg):
self.msg = msg

def __str(self):
return repr(self.msg)
pass

class StrictModeColumnCountMismatchException(Exception):

Expand Down Expand Up @@ -738,7 +697,7 @@ class MaterializedFileState(object):

def read_file_using_csv(self):
# This is a hack for utf-8 with BOM encoding in order to skip the BOM. python's csv module
# has a bug which prevents fixing it using the proper encoding, and it has been encountered by
# has a bug which prevents fixing it using the proper encoding, and it has been encountered by
# multiple people.
if self.encoding == 'utf-8-sig' and self.lines_read == 0 and not self.skipped_bom:
try:
Expand Down Expand Up @@ -1152,7 +1111,7 @@ class QOutput(object):
s = []
s.append('status=%s' % self.status)
if self.error is not None:
s.append("error=%s" % self.error.msg)
s.append("error=%s" % self.error.message)
if len(self.warnings) > 0:
s.append("warning_count=%s" % len(self.warnings))
if self.data is not None:
Expand Down Expand Up @@ -1349,34 +1308,34 @@ class QTextAsData(object):
except EmptyDataException,e:
warnings.append(QWarning(e,"Warning - data is empty"))
except MissingHeaderException,e:
error = QError(e,e.msg,117)
error = QError(e,e.message,117)
except FileNotFoundException, e:
error = QError(e,e.msg,30)
error = QError(e,e.message,30)
except sqlite3.OperationalError, e:
msg = str(e)
error = QError(e,"query error: %s" % msg,1)
msg = e.message
error = QError(e, "query error: %s" % msg,1)
if "no such column" in msg and effective_input_params.skip_header:
warnings.append(QWarning(e,'Warning - There seems to be a "no such column" error, and -H (header line) exists. Please make sure that you are using the column names from the header line and not the default (cXX) column names'))
except ColumnCountMismatchException, e:
error = QError(e,e.msg,2)
error = QError(e, e.message, 2)
except (UnicodeDecodeError, UnicodeError), e:
error = QError(e,"Cannot decode data. Try to change the encoding by setting it using the -e parameter. Error:%s" % e,3)
error = QError(e,"Cannot decode data. Try to change the encoding by setting it using the -e parameter. Error:%s" % e.message, 3)
except BadHeaderException, e:
error = QError(e,"Bad header row: %s" % e.msg,35)
error = QError(e,"Bad header row: %s" % e.message, 35)
except CannotUnzipStdInException,e:
error = QError(e,"Cannot decompress standard input. Pipe the input through zcat in order to decompress.",36)
except UniversalNewlinesExistException,e:
error = QError(e,"Data contains universal newlines. Run q with -U to use universal newlines. Please note that q still doesn't support universal newlines for .gz files or for stdin. Route the data through a regular file to use -U.",103)
except UnprovidedStdInException,e:
error = QError(e,"Standard Input must be provided in order to use it as a table",61)
except CouldNotConvertStringToNumericValueException,e:
error = QError(e,"Could not convert string to a numeric value. Did you use `-w nonnumeric` with unquoted string values? Error: %s" % e.msg,58)
error = QError(e,"Could not convert string to a numeric value. Did you use `-w nonnumeric` with unquoted string values? Error: %s" % e.message,58)
except CouldNotParseInputException,e:
error = QError(e,"Could not parse the input. Please make sure to set the proper -w input-wrapping parameter for your input, and that you use the proper input encoding (-e). Error: %s" % e.msg,59)
error = QError(e,"Could not parse the input. Please make sure to set the proper -w input-wrapping parameter for your input, and that you use the proper input encoding (-e). Error: %s" % e.message,59)
except ColumnMaxLengthLimitExceededException,e:
error = QError(e,e.msg,31)
error = QError(e,e.message,31)
except MissingSqliteBckModuleException, e:
error = QError(e,e.msg,79)
error = QError(e,e.message,79)
except KeyboardInterrupt,e:
warnings.append(QWarning(e,"Interrupted"))
except Exception, e:
Expand Down Expand Up @@ -1481,12 +1440,12 @@ class QOutputPrinter(object):
def print_errors_and_warnings(self,f,results):
if results.status == 'error':
error = results.error
print >>f,error.msg
print >>f,error.message
if self.show_tracebacks:
print >>f,error.traceback

for warning in results.warnings:
print >>f,"%s" % warning.msg
print >>f,"%s" % warning.message

def print_analysis(self,f_out,f_err,results):
self.print_errors_and_warnings(f_err,results)
Expand Down