youxinren / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 0 forks source link

Non informative exceptions #145

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create broken mapping
2. yaml.load()

What is the expected output? 
  org.yaml.snakeyaml.error.YAMLException: Cannot instantiate class MySuperClass, position: line 20, col 10

What do you see instead?
Absolute non informative stacktrace

org.yaml.snakeyaml.error.YAMLException: java.lang.InstantiationException
        *** stripped 50 useless calls
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:411)
    at com.fixy.CoreFixy.loadEntities(CoreFixy.java:115)
    at com.fixy.CoreFixy.load(CoreFixy.java:136)

What version of SnakeYAML are you using? On what Java version?
snake 1.10; java 1.6

Please provide any additional information below. (Often a failing test is
the best way to describe the problem.)

It would be great if you provide any human readable information in YAMLException
1. Position in file
2. Class name whick cannot be instantiate

Original issue reported on code.google.com by theasp...@gmail.com on 24 Apr 2012 at 11:21

GoogleCodeExporter commented 9 years ago
SnakeYAML has a lot of tests where the error is shown (feel free to take the 
source and run the tests).
Without a test case it is not clear what is failing and why the error is not 
clear enough. I am afraid in this particular case the error is that the class 
does not have a public empty constructor. (In this case the file position does 
not help to fix the problem :)
Please provide a test case.

Original comment by py4fun@gmail.com on 30 Apr 2012 at 10:08

GoogleCodeExporter commented 9 years ago
Actually, problem was abstract class. So exception shouldn't be "cannot 
instantiate something in big hierarchy of classes when parsing one of yaml 
files", but "Cannot instantiate MySuperClass: no public constructor, or 
abstract class". Moreover you can show position in yaml file (this information 
is available at exception point), so there was no need to meditate over yaml or 
look over tests and sources. 

In this case I was forced to dig into parser sources, to find out problem class.

Original comment by theasp...@gmail.com on 2 May 2012 at 3:07

GoogleCodeExporter commented 9 years ago
Indeed for some exceptions the line number is shown for exception.toString() 
and not shown for exception.getMessage()

Original comment by py4fun@gmail.com on 2 May 2012 at 10:55

GoogleCodeExporter commented 9 years ago
Fixed.
Check the test: 
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/issues/issue145/LineNumberInExceptionTest.java

Original comment by py4fun@gmail.com on 2 May 2012 at 11:16

GoogleCodeExporter commented 9 years ago
Perfect! thank you very much.

Original comment by theasp...@gmail.com on 3 May 2012 at 2:27

GoogleCodeExporter commented 9 years ago
It will be delivered in version 1.11:
http://code.google.com/p/snakeyaml/wiki/changes

Original comment by py4fun@gmail.com on 4 May 2012 at 6:49