majintao0131 / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

wish: error message indicating parsed tree #104

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to dispose of an alternate, more explicit form of error messages, 
e.g. through a long_what() function.

Let me refer to the example

- name: Ogre
  position: [0, 5, 0]
  powers:
    - name: Club
      damage: 10
    - name: Fist
      damage: 8

When attempting to extract non-existing elements, I would like to get error 
messages like the following:

doc[0]["powers"][1]["alias"]
=> "error in node 0->powers->1 (line 3): key 'alias' not found"

doc[0]["powers"][3]["name"]
=> "error in node 0->powers (line 3): sequence has only 2 entries, index 3 is 
invalid"

doc[0]["powers"][1][2]
=> "error in node 0->powers->1 (line 3): node is map, not a sequence"

doc[0]["powers"][1]["name"]["given"]
=> "error in node 0->powers->1->name (line 4): node is a scalar, not a map"

Original issue reported on code.google.com by Joachim....@gmail.com on 1 May 2011 at 8:26

GoogleCodeExporter commented 9 years ago
I think some of this may work. For example, I like the "node is a map, not a 
sequence" type error, and even "sequence has only 2 entries, index 3 is 
invalid". However, giving the path may not work, for a couple of reasons:

1. The key might be a long scalar with characters that we don't really want to 
print (e.g., newlines)
2. The key might be a complex data type itself, e.g.:

[1, 2]: [3, 4]

Original comment by jbe...@gmail.com on 3 May 2011 at 10:01

GoogleCodeExporter commented 9 years ago
At the very least, line / column information pertaining to the badly casted 
value would be *EXTREMELY* helpful.  I perused the source a tiny bit, and don't 
really understand why each Node doesn't just get a Mark indicating where that 
node begins.  This Mark could then be used for the error messages rather than 
0, 0.  That would be very helpful and save a lot of time.

Original comment by woodswal...@gmail.com on 10 Jun 2014 at 11:11

GoogleCodeExporter commented 9 years ago
Amendment after playing around with it more - you really need the whole key.  
As Joachim points out, when only one asked-for key does not exist, and it's 
buried in a nest of functions, it is very difficult to find out why your 
program is crashing even though the fix is usually ridiculously simple (add 
that key to your yaml).

Original comment by woodswal...@gmail.com on 11 Jun 2014 at 12:11

GoogleCodeExporter commented 9 years ago
Issue 238 has been merged into this issue.

Original comment by jbe...@gmail.com on 24 Jan 2015 at 10:32

GoogleCodeExporter commented 9 years ago
This issue has moved to github: https://github.com/jbeder/yaml-cpp/issues/104

Original comment by jbe...@gmail.com on 30 Mar 2015 at 1:23