From 2f5a481cc31cfc48ac4eafb4a23f44d9e39e479e Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Fri, 15 Jun 2018 09:54:11 +1000 Subject: [PATCH] Detect when there is no document X to update --- yq.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/yq.go b/yq.go index ba803ead..4a6e5856 100644 --- a/yq.go +++ b/yq.go @@ -29,7 +29,7 @@ var log = logging.MustGetLogger("yq") func main() { cmd := newCommandCLI() if err := cmd.Execute(); err != nil { - fmt.Println(err.Error()) + log.Error(err.Error()) os.Exit(1) } } @@ -283,6 +283,9 @@ func mapYamlDecoder(updateData updateDataFn, encoder *yaml.Encoder) yamlDecoderF errorReading = decoder.Decode(&dataBucket) 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 } else if errorReading != nil { return fmt.Errorf("Error reading document at index %v, %v", currentIndex, errorReading)