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

NullPointerException in JsonEncoder #131

Open
jlandahl opened this issue Sep 16, 2022 · 6 comments
Open

NullPointerException in JsonEncoder #131

jlandahl opened this issue Sep 16, 2022 · 6 comments

Comments

@jlandahl
Copy link

jlandahl commented Sep 16, 2022

I have a lambda that I've compiled with GraalVM into a native binary. When I try to test it I get the following:

timestamp=2022-09-16T20:32:51.642769Z level=ERROR thread=#zio-fiber-0 message="" cause="Exception in thread "zio-fiber-6" java.lang.NullPointerException: null
at zio.json.JsonEncoder$$anon$2.unsafeEncode(JsonEncoder.scala:124)
at foo.FooLambda.apply(FooLambda.scala:10)
at zio.lambda.internal.LoopProcessor.Live.loop(LoopProcessor.scala:32)
at zio.lambda.ZLambda.run(ZLambda.scala:24)"
END RequestId: 5f9c59f2-6e6d-4418-98bb-05bbd98d466c
REPORT RequestId: 5f9c59f2-6e6d-4418-98bb-05bbd98d466c Duration: 366.76 ms Billed Duration: 722 ms Memory Size: 512 MB Max Memory Used: 95 MB Init Duration: 354.70 ms
RequestId: 5f9c59f2-6e6d-4418-98bb-05bbd98d466c Error: Runtime exited with error: exit status 1
Runtime.ExitError

Since it's happening in JsonEncoder's string encoder, I'm guessing that the program ran, but then blew up when trying to render the return string to JSON. Here's the program in question:

object FooLambda extends ZLambda[LambdaEvent, String] {
  override def apply(event: LambdaEvent, context: Context): Task[String] =
    ZIO.scoped(FooApp.program).map { case (created, deleted) => s"Created: $created, Deleted: $deleted" }
}

Line 3 here is line 10 in the traceback.

Any tips on how to debug this?

@dbuschman7
Copy link

  • How about splitting up the line in many lines to isolate exactly which part is causing the error.
  • Also, see if you can call the encoder directly to see which field is giving you the error.
  • Send JSON back already encoded

@jlandahl
Copy link
Author

How about splitting up the line in many lines to isolate exactly which part is causing the error.

The exception is thrown in the JsonEncoder for strings, which suggests to me that my code has already run and it's trying to turn the returned string into JSON.

Send JSON back already encoded

If you look at how ZLambda is defined:

abstract class ZLambda[E: JsonDecoder, A: JsonEncoder] extends ZIOAppDefault ...

I don't have any control over the encoding process. It's called automatically after my program returns a string.

@jrmsamson
Copy link
Contributor

Hi @jlandahl,

Can you try to wrap the string with a case class and provide an implicit JsonEncoder for it and see what you get?

BTW, what version of zio-lambda are you using? I'll try to take some time to look into this.

@jlandahl
Copy link
Author

This is happening with 1.0.0-RC6. I'll try what you suggest with a case class and report back.

@jrmsamson
Copy link
Contributor

@jlandahl still having this issue? If not, I'm gonna close this one.

@dbuschman7
Copy link

@jlandahl This is working for us right now:

object ProfileQueryLambda extends ZLambda[AwsAPIGatewayProxyRequestEvent, LambdaResponse]

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

No branches or pull requests

3 participants