Skip to content

createItem not serializing Nothings correctly #23

@tillydray

Description

@tillydray

We are using katip for logging. So we want to create a Rollbar.Item from a Katip.Item and we have this function

mkRollbarItem :: Katip.LogItem a => Katip.Item a -> Rollbar.Item
mkRollbarItem katipItem =
  let payload =
        Rollbar.PayloadMessage $
          Rollbar.Message
            { Rollbar.messageBody =
                LT.toStrict . TB.toLazyText . coerce $
                  Katip._itemMessage katipItem
            , Rollbar.messageMetadata = katipItemToObject katipItem
            }
   in
      Rollbar.Item
        { Rollbar.itemEnvironment = Rollbar.Environment "production"
        , Rollbar.itemBody = Rollbar.Body payload
        , Rollbar.itemLevel =
            katipSeverityToRollbarLevel $
              Katip._itemSeverity katipItem
        , Rollbar.itemPlatform = Nothing
        , Rollbar.itemLanguage = Just "Haskell"
        , Rollbar.itemFramework = Nothing
        , Rollbar.itemRequest = Nothing
        , Rollbar.itemServer = Nothing
        , Rollbar.itemNotifier = Rollbar.Notifier "" ""
        }

Note that both Rollbar.itemServer and Rollbar.itemPlatform are listed as Maybes in the Rollbar.Client docs. And yet, we get this error. The ellipsis is irrelevant stuff

(StatusCodeException (Response {responseStatus = Status {statusCode = 422, statusMessage = "Unprocessable Entity"}, ... "{\n \"err\": 1,\n \"message\": \"Invalid format. data.platform should be string. data.server should be object.\"\n}")))

So we did

let rollbarItem = mkRollbarItem katipItem
_ <- Debug.trace (LBS.unpack $ Aeson.encode rollbarItem) (Rollbar.createItem rollbarItem)

and noticed that platform, server, and other Nothings were serialized as {"server":null, "platform":null, ...}, which seems to make rollbar api unhappy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions