haxetink / tink_await

Haxe async/await
MIT License
58 stars 15 forks source link

Compile fails with no errors in end-user code (another "can't get started" bug) #20

Closed jcward closed 6 years ago

jcward commented 6 years ago

Hi Juraj / Ben,

Sorry this isn't a very actionable bug report (because I cannot attach reproduction code), but I thought I'd report my experience anyway:

I was exploring and evaluating both haxe-continuation and tink_await for a nodejs http server project, and at one point while I was testing tink_await, compilation failed with the following errors. You'll notice that none of the errors point to my end-user code. As such, this error message stumped me, and I couldn't pinpoint it to any specific change, hence I became suspicious of the amount of magic happening (and that'd I'd have to support it for my team), and I eventually gave up on tink_await.

third_party/tink/macro/Positions.hx:48: characters 11-29 : Class<haxe.macro.Context> has no field fatalError
third_party/tink/macro/Positions.hx:24: characters 8-26 : Class<haxe.macro.Context> has no field currentPos
third_party/tink/macro/Positions.hx:40: characters 12-21 : Null<tink.core.Pos> should be haxe.macro.Position
third_party/tink/macro/Positions.hx:40: characters 12-21 : tink.core.Pos should be haxe.macro.Position
third_party/tink/macro/Positions.hx:40: characters 12-21 : haxe.PosInfos should be haxe.macro.Position
third_party/tink/macro/Positions.hx:40: characters 12-21 : { methodName : String, lineNumber : Int, fileName : String, ?customParams : Null<Array<Dynamic>>, className : String } should be haxe.macro.Position
third_party/tink/macro/Positions.hx:40: characters 12-21 : { methodName : String, lineNumber : Int, fileName : String, ?customParams : Null<Array<Dynamic>>, className : String } should be { min : Int, max : Int, file : String }
third_party/tink/macro/Positions.hx:40: characters 12-21 : { methodName : String, lineNumber : Int, fileName : String, ?customParams : Null<Array<Dynamic>>, className : String } has no field file
third_party/tink/macro/Positions.hx:40: characters 12-21 : For function argument 'pos'
third_party/tink/macro/Positions.hx:38: lines 38-44 : Void should be Dynamic
third_party/tink/macro/Exprs.hx:293: characters 11-27 : Class<haxe.macro.Context> has no field makeExpr
third_party/tink/macro/Positions.hx:19: characters 27-41 : Class<haxe.macro.Context> has no field typeof
third_party/tink/macro/Positions.hx:29: characters 11-25 : Class<tink.macro.Bouncer> has no field bounce
third_party/tink/macro/Positions.hx:51: characters 32-37 : String should be Null<tink.core.ErrorCode>
third_party/tink/macro/Positions.hx:51: characters 32-37 : String should be tink.core.ErrorCode
third_party/tink/macro/Positions.hx:51: characters 32-37 : For optional function argument 'code'
third_party/tink/macro/Positions.hx:56: characters 4-19 : Class<haxe.macro.Context> has no field warning
third_party/tink/macro/Positions.hx:61: characters 29-35 : String should be Null<tink.core.ErrorCode>
third_party/tink/macro/Positions.hx:61: characters 29-35 : String should be tink.core.ErrorCode
third_party/tink/macro/Positions.hx:61: characters 29-35 : For optional function argument 'code'
third_party/tink/macro/Types.hx:20: characters 13-28 : Class<haxe.macro.Context> has no field getType
third_party/tink/macro/Types.hx:150: characters 11-25 : Class<haxe.macro.Context> has no field follow
third_party/tink/macro/Types.hx:92: characters 27-67 : Class<haxe.macro.TypeTools> has no field applyTypeParameters
third_party/tink/macro/Types.hx:97: characters 17-35 : Class<haxe.macro.Context> has no field currentPos
third_party/tink/macro/Exprs.hx:349: characters 16-30 : Class<haxe.macro.Context> has no field typeof
third_party/tink/macro/Types.hx:189: characters 20-40 : Class<haxe.macro.Context> has no field getLocalType
third_party/tink/macro/Exprs.hx:50: characters 14-32 : Class<haxe.macro.Context> has no field currentPos
third_party/tink/macro/Exprs.hx:66: characters 12-31 : Class<haxe.macro.Context> has no field getPosInfos
third_party/tink/macro/TypeMap.hx:28: characters 24-35 : haxe.macro.Type has no field toString
third_party/tink/macro/TypeMap.hx:28: characters 39-50 : haxe.macro.Type has no field toString
third_party/tink/MacroApi.hx:37: characters 11-40 : Class<haxe.macro.Context> has no field currentPos
third_party/tink/macro/ClassBuilder.hx:23: characters 15-36 : Class<haxe.macro.Context> has no field getLocalClass
third_party/tink/macro/ClassBuilder.hx:26: characters 15-37 : Class<haxe.macro.Context> has no field getBuildFields
third_party/tink/macro/ClassBuilder.hx:66: characters 25-45 : Class<haxe.macro.Context> has no field getTypedExpr
third_party/tink/macro/ClassBuilder.hx:68: characters 26-35 : You can't iterate on a Dynamic value, please specify Iterator or Iterable
third_party/tink/macro/ClassBuilder.hx:114: characters 8-23 : Class<haxe.macro.Context> has no field warning
third_party/tink/syntaxhub/FrontendContext.hx:10: characters 0-21 : You cannot access the sys package while targeting js (for sys.FileSystem)
third_party/tink/syntaxhub/FrontendPlugin.hx:5: characters 38-53 :     referenced here

Beyond that, my experience has been that haxe-continuation is much easier to integrate, lighter weight (fewer dependencies), and just works for native JS functions with their natural callback signatures. It's a shame it doesn't support error handling / try / catch. But I suppose I could maybe hack something together.

Maybe I have one actionable item: The tink_await docs / examples don't readily show how to wrap a native JS function, handling error and success. The only example I found was a trivial timeout. I hacked around to get this hideous monstrosity:

  static function oauth_helper(oauth2Client:OAuth2, code:String)
  {
    return Future.async(function(cb) {
      oauth2Client.getToken(code, function(err:{}, tokens:{}) {
        if (err!=null) {
          // Weird, I have to wrap err in data... twice. Probably due
          // to the dynamic catch. Hmm...
          cb(Failure({ data:{ data:err } }));
          // cb(Success(null)); // Doesn't require try/catch...
        } else {
          cb(Success(tokens));
        }
      });
    });
  }
jcward commented 6 years ago

FYI, this is the lovely JS callback (and faux multi-var assignment) that haxe-continuation implements:

image

And all this requires is a typical extern definition:

image

kevinresol commented 6 years ago

Usually I encounter this or similar error when I forgot to wrap using tink.MacroApi with #if macro. Is it your case?

kevinresol commented 6 years ago

If it is not by you, maybe you can try updating all your tink libraries to latest git version. Otherwise can you show the versions of your tink libraries?

jcward commented 6 years ago

It might have had something to do with conflicting using tink.CoreApi and import <something else> -- I vaguely trying to use the macro API in the same file ask Tink, and it exploded.

I tried again to create some wrapper to get the syntax I wanted out of Tink, and also exploring the exception handling. But again I failed to get to a workable API.

Ah well. Perhaps it's simply not for me.