Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

logging library doesn't support Exceptions

Offen
#172 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

@IzaakGough arbeitet bereits daran.

Seit 01.6.2026.

  • #277 von @IzaakGough — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
52/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
python

Rechercherichtung

Beginne in firebase_functions/logger.py, insbesondere bei error(), write() und _entry_from_args(), und vergleiche dann das dokumentierte Firebase-Logging-Beispiel mit dem hier gezeigten Fehler bei der JSON-Serialisierung. Die Aufgabe ist erledigt, wenn das Logging einer Exception keinen Fehler mehr auslöst und die Logging-API den vollständigen Stacktrace der Exception in die Funktionslogs aufnimmt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

feature-request

The logger in firebase_functions doesn't seem to provide reasonable support for exceptions.

In the example, firebase suggests extracting a portion of the error and including it:

try
...
except:
    e = sys.exc_info()[0]
    # Attach an error object as the second argument
    logger.error("Unable to read quote from Firestore, sending default instead", error=e)

However this fails with an error:

../../../../Library/Caches/pypoetry/virtualenvs/oasis-zYbk3Ww0-py3.11/lib/python3.11/site-packages/firebase_functions/logger.py:130: in error
    write(_entry_from_args(LogSeverity.ERROR, *args, **kwargs))
../../../../Library/Caches/pypoetry/virtualenvs/oasis-zYbk3Ww0-py3.11/lib/python3.11/site-packages/firebase_functions/logger.py:95: in write
    print(_json.dumps(_remove_circular(entry)), file=write_file)
../../../../.pyenv/versions/3.11.7/lib/python3.11/json/__init__.py:231: in dumps
    return _default_encoder.encode(obj)
../../../../.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:200: in encode
    chunks = self.iterencode(o, _one_shot=True)
../../../../.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:258: in iterencode
    return _iterencode(o, 0)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <json.encoder.JSONEncoder object at 0x10166ee10>, o = <class 'TypeError'>

    def default(self, o):
        """Implement this method in a subclass such that it returns
        a serializable object for ``o``, or calls the base implementation
        (to raise a ``TypeError``).
    
        For example, to support arbitrary iterators, you could
        implement default like this::
    
            def default(self, o):
                try:
                    iterable = iter(o)
                except TypeError:
                    pass
                else:
                    return list(iterable)
                # Let the base class default method raise the TypeError
                return JSONEncoder.default(self, o)
    
        """
>       raise TypeError(f'Object of type {o.__class__.__name__} '
                        f'is not JSON serializable')
E       TypeError: Object of type type is not JSON serializable

../../../../.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:180: TypeError

Moreover it's not really an ideal API to log a subset of an exception. Ideally the entire stack trace would be included.

If you instead simply print the error, you can see a reasonable stack trace in the logs for the function.

I'd expect the example to not throw. I'd also expect the logging API to explicitly support logging Exceptions with stack traces

Vorherrschende Sprache
Python
Sterne
167
Forks
36
Ø Merge
4 T. 3 Std.
Gemergte PRs (30 T.)
1

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus firebase/firebase-functions-python

Alle Issues in firebase/firebase-functions-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.