[Possible Parser Bug] Key entries with the token ','
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
Piste de recherche
Le payload ne mentionne aucun fichier source ni aucun test ; commencez par reproduire l’exemple YAML minimal et examiner comment Psych signale l’emplacement de l’erreur de syntaxe. C’est terminé lorsque la clé invalide est diagnostiquée à sa ligne réelle, avec une couverture de régression pour l’exemple et ses entrées valides environnantes.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Hello ruby maintainers of psych-yaml,
I may have found a small bug. Perhaps it is not a "real" bug, but the
error reporting by psych was strange still, so I report it here.
First, so that you can reproduce it, here is the minimum example
to demonstrate the problem:
---
bla: bar
,abc: foo
Edit: Seems github wants markdown parsing, so the line before bla: is
actually three times - which I think is the default header for yaml files.
So the problem is the second entry, called ",abc", in particular the key
',' there. If this ',' token is removed, or if we put this in '' strings
such as:
',abc': foo
Then it works.
If I load this right now, I get:
#<Psych::SyntaxError: (foo.yml): did not find expected key while parsing a block mapping at line 2 column 1>
The problem is that Psych actually reports the wrong line. It reports the
error very early on.
How did I discover this problem?
I have a huge yaml file, about 20.000 lines of code. I was making such
a change with a leading ',' token and forgot the next day where I made
it.
So when I tried to load the .yml file, psych was pointing out that there
was an error. But the message it showed me was not useful - the error
was not on that particular line.
It took me some attempts to isolate the faulty lines, by cutting down
on a copy of that big .yml file.
So what is my proposal to change this?
Well, I assume here that the specification is clear and that leading
',' tokens may not be correct. I don't know whether this is true or
not, but let's first assume this is the case, as otherwise that behaviour
has to change as well.
My gripe here is mostly with psych reporting the wrong line. It seems
to instead report the very first entry found, rather than the line itself.
You can test this yourself. Simply add more correct lines to that .yml
file, before the faulty line, and afterwards, yet psych will still only
always claim that the error happens near the beginning of the yaml
dataset, which I think is not ideal. The real error is only (!) on the
line with the ',' token. At the least I believe this would be more
useful to report this to the end user too.
You may of course say that the current behaviour of psych is correct,
which may be true - but the current behaviour is not really very
helpful to users who try to debug the problem at hand. At the least in
my use case, it would have been better to specifically report which
line was flawed. No clue if there is a good simple way to change this
behaviour, but perhaps in the long run, if anyone thinks about making
psych a bit more user-friendly, similar how the did-you-mean gem
helped improve (some) error messages for ruby, then perhaps something
similar could happen to psych.
I am using psych all the time now, used to use syck instead for
many, many years, but psych seems to work better now - and perhaps
being stricter than syck also was the right decision in the long
run.
- Langage dominant
- Ruby
- Étoiles
- 596
- Forks
- 224
- Merge moyen
- 5 h 50 min
- PR mergées (30 j)
- 3
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de ruby/psych
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Documentation
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 stringsPeut-être pris @Halvanhelv l’a pris il y a 42 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 55/100
-
Difficulté 4/5 3-5 jours Accessibilité débutants 68/100
-
Difficulté 4/5 3-5 jours Accessibilité débutants 52/100
Toutes les issues de ruby/psych
Issues similaires
-
Lint/NoReturnInMemoization flags `return` in local variable `||=` and `&&=` assignmentsPeut-être pris @RaphaelFakhri l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
Shopify/ruby-style-guide#815 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
zerocracy/judges-action#2849 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
bigbluebutton/bigbluebutton#26166 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
TarteelAI/quranic-universal-library#916 ·
Les mainteneurs répondent en général sous 1 jour
-
good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
Les mainteneurs répondent en général sous 1 jour