Add more tests around JSON/YAML decoding from the CLI

Switch the ignore stream errors behavior to print a Warningf on
failure to parse, not v(2)
This commit is contained in:
Clayton Coleman
2015-01-14 12:38:36 -05:00
parent abc621759a
commit 31413c8727
4 changed files with 39 additions and 5 deletions

View File

@@ -337,7 +337,10 @@ type StreamVisitor struct {
}
// NewStreamVisitor creates a visitor that will return resources that were encoded into the provided
// stream. If ignoreErrors is set, unrecognized or invalid objects will be skipped and logged.
// stream. If ignoreErrors is set, unrecognized or invalid objects will be skipped and logged. An
// empty stream is treated as an error for now.
// TODO: convert ignoreErrors into a func(data, error, count) bool that consumers can use to decide
// what to do with ignored errors.
func NewStreamVisitor(r io.Reader, mapper *Mapper, source string, ignoreErrors bool) Visitor {
return &StreamVisitor{r, mapper, source, ignoreErrors}
}
@@ -356,7 +359,7 @@ func (v *StreamVisitor) Visit(fn VisitorFunc) error {
info, err := v.InfoForData(ext.RawJSON, v.Source)
if err != nil {
if v.IgnoreErrors {
glog.V(2).Infof("Unable to read item from stream %q: %v", err)
glog.Warningf("Could not read an encoded object from %s: %v", v.Source, err)
glog.V(4).Infof("Unreadable: %s", string(ext.RawJSON))
continue
}