Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Cannot invoke "cats.effect.IO.map(scala.Function1)" because "fa" is null #493

Copy link
Copy link
@DenisNovac

Description

@DenisNovac
Issue body actions

Recently i stuck with this error message:

java.lang.NullPointerException: Cannot invoke "cats.effect.IO.map(scala.Function1)" because "fa" is null

As is turned out, it means the mock can't find configured return answer for incoming request. The same as here:

whenF(mock.method("a")).thenReturn(response)
mock.method("b") // b is not configured input

I believe it is pretty much the same error as this:

You have a NullPointerException here:
-> at org.scalatest.OptionValues$Valuable.value(OptionValues.scala:126)
because this method call was *not* stubbed correctly:
-> at scala.Option.orElse(Option.scala:477)
foo.returnsGenericOption(ValueClass(HOLA));

But for some reason effect test libraries (i tried this with pure Cats Effect and Weaver) don't show the correct message.

Most definitely (if you didn't just messed up the inputs and outputs) you need to use eqTo + some equality implicit. Example for MockitoCats trait:

 implicit val reqEq: Eq[Request] = (x: Request, y: Request) =>
    x.value == y.value // some complex object equality check

whenF(mock.method(eqTo(request))).thenReturn(response)

This is mostly for searching purposes of future users since i had troubles with debugging this thing. Guess it could be closed without any actions.

rudolmi, jessebutterfield and erikv85

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.