olucurious / olucurious/PyFCM

The InvalidDataError exception logs multi line text (JSON)

Open
#350 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
814
Forks
209
PR merge metrics
No merged PRs in 30d

Description

Summary

The InvalidDataError Exception, when logged, outputs multi-line text (which happens to also be JSON) which is not properly handled by things like Google Cloud Log Explorer. This makes filtering logs difficult.

https://github.com/olucurious/PyFCM/blob/15cdc602c182c6a0df59e630b359321b9246a2e3/pyfcm/baseapi.py#L212

Resolution
  • Remove newlines from response.text.
  • (Or) Detect that the content is JSON and un-pretty-print it.
Steps to reproduce

Using pyfcm==2.0.4

from pyfcm import FCMNotification
push_service = FCMNotification(
    service_account_file="local_creds.json",
    project_id="xxx",
)

result = push_service.notify(
    fcm_token="cheeseburgers",
    notification_title=title,
    notification_body=message_body,
)
Traceback (most recent call last):
  File "/home/dan/xxx/dan-test.py", line 64, in <module>
    result = push_service.notify(
  File "/home/dan/xxx/venv/lib/python3.10/site-packages/pyfcm/fcm.py", line 67, in notify
    return self.parse_response(response)
  File "/home/dan/xxx/venv/lib/python3.10/site-packages/pyfcm/baseapi.py", line 212, in parse_response
    raise InvalidDataError(response.text)
pyfcm.errors.InvalidDataError: {
  "error": {
    "code": 400,
    "message": "The registration token is not a valid FCM registration token",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode": "INVALID_ARGUMENT"
      }
    ]
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pyfcm/baseapi.py at the parse_response call on line 212 and reproduce the InvalidDataError with the response shown in the issue. Verify that the resulting exception text is emitted on one line while preserving the error content, then confirm the example no longer produces multi-line log output.

Written by the indexing model from the issue text.

Assessment

Tech stack
firebase, python
Domain
api, observability
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.