Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass duplicated mapping key ? #345

Closed
Aktanee opened this issue May 2, 2017 · 6 comments
Closed

Bypass duplicated mapping key ? #345

Aktanee opened this issue May 2, 2017 · 6 comments

Comments

@Aktanee
Copy link

Aktanee commented May 2, 2017

When loading a YAML file with a duplicate key, I got this message error.

{
    "name":"YAMLException",
    "reason":"duplicated mapping key",
    "mark":{...},
    "message":"duplicated mapping key at line 388, column 5:\n        last_published: \"Last published\"\n        ^"
}"

Is there a way to bypass this error and take the last value input, here, to have duplicate as true ?

test:
      duplicate: false
      duplicate: true
@puzrin
Copy link
Member

puzrin commented May 2, 2017

No way. Duplicated keys are not allowed both in json and yaml.

@Aktanee
Copy link
Author

Aktanee commented May 2, 2017

Thanks for answering that fast, what I meant, if it wasn't clear was to have one key at the end with the last valor given (as http://www.yamllint.com/ do).

@puzrin
Copy link
Member

puzrin commented May 2, 2017

I can't comment that site. May be it has reasons to not follow spec. But we checked carefully, prior to add throwing error for duplicated keys.

@Aktanee
Copy link
Author

Aktanee commented May 2, 2017

Ok thanks, I understand

@Aktanee Aktanee closed this as completed May 2, 2017
@arcanis
Copy link

arcanis commented Nov 27, 2020

@puzrin By any chance, would you be open to reevaluate this? We're using js-yaml on Yarn (our lockfiles are now regular Yaml), and to make our users' life easier we try to gracefully recover from lockfile merge conflicts (basically we parse both current and incoming versions of the lockfile, then merge them together). It turns out that in some circumstances Git will generate a bogus lockfile that duplicates some keys.

In our case it's not a big deal (it's best effort recovery, and both entries contain the same data anyway), but the lack of option to signal to js-yaml that it should just ignore the problem means that we sometimes have to throw pretty annoying errors:

➤ YN0046: The individual variants of the lockfile failed to parse

When that happens, there's no other choice for the user than remove the lockfile, and lose all their current locked resolutions. It's not a great experience 🙁

@puzrin
Copy link
Member

puzrin commented Nov 27, 2020

@arcanis ok, create a new issue with this details please. Need to think.

@arcanis arcanis mentioned this issue Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants