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

Remove duplicate mapping key #4145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gogolok
Copy link
Contributor

@gogolok gogolok commented Dec 17, 2024

The error codes 60003 and 290013 appear twice. While many YAML parsers can cope with duplicate mapping keys, many parser will error out.
External tools, like for example
go-cfclient's gen_error.go, cannot update to more recent major versions of their YAML parser library:

yaml: unmarshal errors:
  line 221: mapping key "60003" already defined at line 216
  line 1036: mapping key "290013" already defined at line 1026
panic: yaml: unmarshal errors:
	  line 221: mapping key "60003" already defined at line 216
	  line 1036: mapping key "290013" already defined at line 1026

Cloud Controller uses psych to parse the errors/*.yml files. Psych uses the latest occurence of a key. Therefore, the most recent duplicate key can be picked to stay in the errors files.

irb(main):001> require 'psych'
=> true
irb(main):002> filepath = "errors/v2.yml"
=> "errors/v2.yml"
irb(main):003* content = File.open(filepath) do |f|
irb(main):004*   Psych.safe_load(f, strict_integer: true)
irb(main):005> end; nil
=> nil
irb(main):006> content[60003]
=> {"name"=>"ServiceInstanceInvalid", "http_code"=>400, "message"=>"The service instance is invalid: %s"}
irb(main):007> content[290013]
=> {"name"=>"SpaceRolesDeletionTimeout", "http_code"=>524, "message"=>"Deletion of roles for space %s timed out before all roles could be deleted"}
  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

@fapo85
Copy link

fapo85 commented Dec 17, 2024

Releated issue:
#2894

The error codes `60003` and `290013` appear twice. While many YAML
parsers can cope with duplicate mapping keys, many parser will error
out.
External tools, like for example
[go-cfclient's gen_error.go](https://github.com/cloudfoundry/go-cfclient/blob/main/tools/gen_error.go),
cannot update to more recent major versions of their YAML parser
library:

```shell
yaml: unmarshal errors:
  line 221: mapping key "60003" already defined at line 216
  line 1036: mapping key "290013" already defined at line 1026
panic: yaml: unmarshal errors:
	  line 221: mapping key "60003" already defined at line 216
	  line 1036: mapping key "290013" already defined at line 1026
```

Cloud Controller uses `psych` to parse the errors/*.yml files. Psych
uses the latest occurence of a key. Therefore, the most recent duplicate
key can be picked to stay in the errors files.

```
irb(main):001> require 'psych'
=> true
irb(main):002> filepath = "errors/v2.yml"
=> "errors/v2.yml"
irb(main):003* content = File.open(filepath) do |f|
irb(main):004*   Psych.safe_load(f, strict_integer: true)
irb(main):005> end; nil
=> nil
irb(main):006> content[60003]
=> {"name"=>"ServiceInstanceInvalid", "http_code"=>400, "message"=>"The service instance is invalid: %s"}
irb(main):007> content[290013]
=> {"name"=>"SpaceRolesDeletionTimeout", "http_code"=>524, "message"=>"Deletion of roles for space %s timed out before all roles could be deleted"}
```
@gogolok gogolok force-pushed the v2_yml_unique_keys branch from a01431e to c0a216a Compare January 21, 2025 13:53
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

Successfully merging this pull request may close these issues.

2 participants