duplicate key diagnostics
currently we have no line number/column where this duplicate key is. ideally report line number:column as well as where the key happened first time.
in gcc it looks like we all know:
rualpe-ws:tmp paf$ cat a.c
void a() {}
void a() {}
rualpe-ws:tmp paf$ gcc a.c
a.c:2:6: error: redefinition of 'a'
void a() {}
^
a.c:1:6: note: previous definition is here
void a() {}
^
1 error generated.
rualpe-ws:tmp paf$
Comments (11)
-
reporter -
I see 2 questions here.
- The position of the duplicate key is reported. If you think this is not the case, please provide a test to show the problem. (otherwise close the issue)
- Reporting of the location of the first occurrence is a separate issue. Let us not mix everything together.
-
reporter - I see only blind error here: https://bitbucket.org/asomov/snakeyaml/src/190f378138123971777405fbabeab704724b1860/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java?at=default&fileviewer=file-view-default#SafeConstructor.java-77 and that is what we get on client side.
- OK, let's not discuss that here.
-
reporter this is in 1.18 version, but link above goes to repo, where I see no changes.
what we get on client side:
Caused by: java.lang.IllegalStateException: duplicate key: global_code at org.yaml.snakeyaml.constructor.SafeConstructor.processDuplicateKeys(SafeConstructor.java:102) at org.yaml.snakeyaml.constructor.SafeConstructor.flattenMapping(SafeConstructor.java:73) at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:184) at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:357) at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:532) at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:184) at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:143) at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:129) at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:505) at org.yaml.snakeyaml.Yaml.load(Yaml.java:436)
-
reporter I see no position in this exception. Only name of key. With files of about 3K lines and that key all over them, this error is very hard to handle by a guy who does it in the middle of the night on a production node...
-
reporter tried 1.19 version. attaching small test.
Connected to the target VM, address: '127.0.0.1:62333', transport: 'socket' Exception in thread "main" java.lang.IllegalStateException: duplicate key: key1 at org.yaml.snakeyaml.constructor.SafeConstructor.processDuplicateKeys(SafeConstructor.java:99) at org.yaml.snakeyaml.constructor.SafeConstructor.flattenMapping(SafeConstructor.java:70) at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:182) at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:443) at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:519) at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:207) at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:196) at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:161) at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:147) at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:524) at org.yaml.snakeyaml.Yaml.load(Yaml.java:437) at com.company.Main.main(Main.java:22) Disconnected from the target VM, address: '127.0.0.1:62333', transport: 'socket'
I would like file name (if known) and line number of an error.
-
- DuplicateKeyException is created
- The line number is reported (it was implemented only for Javabeans - that was the confusion)
- Filename is not known - SnakeYAML works with streams, not with files.
Feel free to check the latest source.
-
Issue
#394was marked as a duplicate of this issue. -
reporter thanks! no file name -- fine with us, we'll add it on a client side. is it possible you'd release this (1.20?)
-
Does it work ? Have you tested it ?
It will be released in 1.20 (should be February 2018)
-
reporter It does work, already incorporated snapshot version into our app:
while constructing a mapping in 'reader', line 6, column 17: down: {speed: 41984} ^ found duplicate key qci in 'reader', line 10, column 17: qci: 7 ^
thanks Andrey! спасибо!
- Log in to comment
коллеги просят добавить "пожалуйста" ;)