Detect when there is no document X to update

This commit is contained in:
Mike Farah 2018-06-15 09:54:11 +10:00
parent 1a4064429d
commit 2f5a481cc3

5
yq.go
View File

@ -29,7 +29,7 @@ var log = logging.MustGetLogger("yq")
func main() { func main() {
cmd := newCommandCLI() cmd := newCommandCLI()
if err := cmd.Execute(); err != nil { if err := cmd.Execute(); err != nil {
fmt.Println(err.Error()) log.Error(err.Error())
os.Exit(1) os.Exit(1)
} }
} }
@ -283,6 +283,9 @@ func mapYamlDecoder(updateData updateDataFn, encoder *yaml.Encoder) yamlDecoderF
errorReading = decoder.Decode(&dataBucket) errorReading = decoder.Decode(&dataBucket)
if errorReading == io.EOF { if errorReading == io.EOF {
if currentIndex < docIndex {
return fmt.Errorf("Asked to process document %v but there are only %v document(s)", docIndex, currentIndex)
}
return nil return nil
} else if errorReading != nil { } else if errorReading != nil {
return fmt.Errorf("Error reading document at index %v, %v", currentIndex, errorReading) return fmt.Errorf("Error reading document at index %v, %v", currentIndex, errorReading)