Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

logging library doesn't support Exceptions

Abierto
#172 3 comentarios 0 reacciones 0 asignados Ver en GitHub

@IzaakGough ya está trabajando en esto.

Desde el 1/6/2026.

  • #277 de @IzaakGough — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
python

Línea de trabajo

Empieza en firebase_functions/logger.py, especialmente en error(), write() y _entry_from_args(), y compara después el ejemplo documentado de logging de Firebase con el fallo de serialización JSON mostrado aquí. La tarea estará terminada cuando registrar una Exception ya no provoque un error y la API de logging incluya el stack trace completo de la Exception en los logs de la función.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
167
Forks
36
Merge medio
4 d 3 h
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de firebase/firebase-functions-python

Todos los issues de firebase/firebase-functions-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.