JSONDecodeError verbose error mesage
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece revisando json.loads e JSONDecodeError; em seguida, leia a discussão existente da issue para entender as opções de design ainda não resolvidas. Defina qual comportamento de contexto e intervalo deve ser suportado e adicione testes que demonstrem a saída detalhada pretendida para JSON malformado.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend
- Tipo de issue
- Funcionalidade
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100