Skip to content

Conversation

@astahlman
Copy link

Prior to this change, if the input file contained invalid SQL it would
be overwritten with an empty file. This change lets the exception
propagate so that the file is left untouched.

➜ format-sql git:(no-overwrite-invalid) cat /tmp/invalid.sql
SELECT foo, bar FROMM snoober;
➜ format-sql git:(no-overwrite-invalid) python format_sql/main.py /tmp/invalid.sql
/tmp/invalid.sql
Traceback (most recent call last):
File "format_sql/main.py", line 148, in
main()
File "format_sql/main.py", line 81, in main
lines = handle_sql_file(filename, args.debug)
File "format_sql/main.py", line 133, in handle_sql_file
sql = format_sql(lines, debug)
File "/Users/andrewstahlman/src/oss/format-sql/format_sql/shortcuts.py", line 20, in format_sql
parsed = list(parse(tokens))
File "/Users/andrewstahlman/src/oss/format-sql/format_sql/parser.py", line 762, in parse
for statement, unused_count in _parse(toks):
File "/Users/andrewstahlman/src/oss/format-sql/format_sql/parser.py", line 755, in _parse
raise InvalidSQL()
format_sql.parser.InvalidSQL
➜ format-sql git:(no-overwrite-invalid) git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
➜ format-sql git:(master) python format_sql/main.py /tmp/invalid.sql
/tmp/invalid.sql

Traceback (most recent call last):
File "format_sql/main.py", line 152, in
main()
File "format_sql/main.py", line 83, in main
_write_back(filename, lines, args.dry_run)
File "format_sql/main.py", line 148, in _write_back
f.write(lines)
TypeError: expected a string or other character buffer object
➜ format-sql git:(master) cat /tmp/invalid.sql
➜ format-sql git:(master)

Prior to this change, if the input file contained invalid SQL it would
be overwritten with an empty file. This change lets the exception
propagate so that the file is left untouched.
@coveralls
Copy link

coveralls commented Dec 21, 2016

Coverage Status

Coverage increased (+0.3%) to 97.097% when pulling 781c643 on astahlman:no-overwrite-invalid into 0c93acb on paetzke:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants