From 8cf21324dc5f708100e301cceb1dbda2ca2e65e0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 1 Jul 2013 14:47:49 -0700 Subject: [PATCH] packer: extra comments on JSON syntax error calc --- packer/template.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packer/template.go b/packer/template.go index 8bb8ce4aa..c94dd8fc3 100644 --- a/packer/template.go +++ b/packer/template.go @@ -75,12 +75,14 @@ func ParseTemplate(data []byte) (t *Template, err error) { // https://groups.google.com/forum/#!topic/golang-nuts/fizimmXtVfc newline := []byte{'\x0a'} + // Calculate the start/end position of the line where the error is start := bytes.LastIndex(data[:syntaxErr.Offset], newline)+1 end := len(data) if idx := bytes.Index(data[start:], newline); idx >= 0 { end = start + idx } + // Count the line number we're on plus the offset in the line line := bytes.Count(data[:start], newline)+1 pos := int(syntaxErr.Offset) - start - 1