kasperpeulen / gist-generator

Create gists from the command line.
MIT License
3 stars 1 forks source link

Handle invalid Dart code better #7

Open kwalrath opened 9 years ago

kwalrath commented 9 years ago

I had a stupid mistake in one of my samples (I'd modified it slightly and not bothered to run it), which caused gist generate to hurl due to an uncaught exception. (See message below.)

I'd rather the generator caught the exception and printed out an error message. Something like this:

No gist generated for "assert": assert/web/main.dart has a syntax error.

Here's what I saw instead (note: it doesn't mention "assert", making it harder to figure out what went wrong):

Unhandled exception:
Uncaught Error: Error in <unknown source>: Unterminated string literal

Error in <unknown source>: Expected to find ')'

Error in <unknown source>: Expected to find ';'

Error in <unknown source>: Expected to find ';'

Error in <unknown source>: Expected a statement

Error in <unknown source>: Unexpected token 'in'

Error in <unknown source>: Expected to find ';'

Error in <unknown source>: Expected an identifier

Error in <unknown source>: Expected to find ';'

Error in <unknown source>: Expected to find ';'

Stack Trace:
#0      _parseSource (package:analyzer/analyzer.dart:78)
#1      parseCompilationUnit (package:analyzer/analyzer.dart:38)
#2      AnalyzerUtil.findLibraries (package:gist/analyzer.dart:10)
#3      Generate._isDartpadAble (http://localhost:50109/gist.dart:125)
#4      ListMixin._filter (dart:collection/list.dart:278)
#5      Object&ListMixin.retainWhere (dart:collection/list.dart:268)
#6      Generate.run.<run_async_body> (http://localhost:50109/gist.dart:51)
#7      Future.Future.microtask.<anonymous closure> (dart:async/future.dart:144)
#8      _microtaskLoop (dart:async/schedule_microtask.dart:43)
#9      _microtaskLoopEntry (dart:async/schedule_microtask.dart:52)
#10     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:96)
#11     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:149)

#0      _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:895)
#1      _microtaskLoop (dart:async/schedule_microtask.dart:43)
#2      _microtaskLoopEntry (dart:async/schedule_microtask.dart:52)
#3      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:96)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:149)
kasperpeulen commented 9 years ago

Oh yeah, I see. I use the analyzer to see which libraries it imports. I'm not sure if i will be able to fix this before I go on holiday though.

kwalrath commented 9 years ago

No worries. The workaround is just to test the code before running gist generate.

Have a great holiday!