JSONDecodeError verbose error mesage
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Feature or enhancement
Proposal:
Example is the best way to start:
import json
try:
raw_json_dict = b"{'a': 1, {'b': 2 'c': 3}}"
letter_to_index = json.loads(raw_json_dict)
except JSONDecodeError as error:
print(error.verbose())
# Printing => verbose error:"'b': 2 'c': 3}"
The problem:
Currently, when getting a JSONDecodeError you can't fully understand where the issue is because of unindecative error message.
The message only gives you the location of the error but not what actually caused the error itself.
For example, when you try to json.loads() a response from a server and you don't know what the content will be.
If you got a JSONDecodeError and you didn't log or save the raw response fron the server, you won't be able to figure out what caused the error and fix it.
The solution
First, I am not here to propose one unique solution, there could be multiple possible solutions. I just want to present the simple one to show its impact.
The solution I proposed in the example makes use of new function inside the JSONDecodeError class.
The verbose function prints the actual characters in which the error occurred and print a range of chars around them to get a context of the error.
Furthermore, the function will be able to get a parameter which will defines the range of characters around the error to get back.
I would very like to hear your opinions of this feature.
Thanks!
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza revisando json.loads y JSONDecodeError; después, lee la discusión existente del issue para entender las opciones de diseño aún no resueltas. Define qué comportamiento de contexto y rango debe admitirse y añade pruebas que demuestren la salida detallada prevista para JSON mal formado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100