// Copyright 2015 Google Inc. All Rights Reserved.
// This file is available under the Apache license.

package errors

import (
	"fmt"
	"strings"

	"github.com/google/mtail/internal/vm/position"
	"github.com/pkg/errors"
)

type compileError struct {
	pos position.Position
	msg string
}

func (e compileError) Error() string {
	return e.pos.String() + ": " + e.msg
}

// ErrorList contains a list of compile errors.
type ErrorList []*compileError

// Add appends an error at a position to the list of errors.
func (p *ErrorList) Add(pos *position.Position, msg string) {
	*p = append(*p, &compileError{*pos, msg})
}

// Append puts an ErrorList on the end of this ErrorList.
func (p *ErrorList) Append(l ErrorList) {
	*p = append(*p, l...)
}

// ErrorList implements the error interface.
func (p ErrorList) Error() string {
	switch len(p) {
	case 0:
		return "no errors"
	case 1:
		return p[0].Error()
	}
	var r strings.Builder
	for _, e := range p {
		r.WriteString(fmt.Sprintf("%s\n", e))
	}
	return r.String()
}

func Errorf(format string, args ...interface{}) error {
	return errors.Errorf(format, args...)
}

// Copyright 2015 Google Inc. All Rights Reserved.
// This file is available under the Apache license.

package errors

import (
	"fmt"

	"github.com/google/mtail/internal/vm/position"
	"github.com/pkg/errors"
)

type compileError struct {
	pos position.Position
	msg string
}

func (e compileError) Error() string {
	return e.pos.String() + ": " + e.msg
}

// ErrorList contains a list of compile errors.
type ErrorList []*compileError

// Add appends an error at a position to the list of errors.
func (p *ErrorList) Add(pos *position.Position, msg string) {
	*p = append(*p, &compileError{*pos, msg})
}

// Append puts an ErrorList on the end of this ErrorList.
func (p *ErrorList) Append(l ErrorList) {
	*p = append(*p, l...)
}

// ErrorList implements the error interface.
func (p ErrorList) Error() string {
	switch len(p) {
	case 0:
		return "no errors"
	case 1:
		return p[0].Error()
	}
	var r string
	for _, e := range p {
		r = r + fmt.Sprintf("%s\n", e)
	}
	return r[:len(r)-1]
}

func Errorf(format string, args ...interface{}) error {
	return errors.Errorf(format, args...)
}

--- 
+++ 
@@ -5,6 +5,7 @@
 
 import (
 	"fmt"
+	"strings"
 
 	"github.com/google/mtail/internal/vm/position"
 	"github.com/pkg/errors"
@@ -40,11 +41,11 @@
 	case 1:
 		return p[0].Error()
 	}
-	var r string
+	var r strings.Builder
 	for _, e := range p {
-		r = r + fmt.Sprintf("%s\n", e)
+		r.WriteString(fmt.Sprintf("%s\n", e))
 	}
-	return r[:len(r)-1]
+	return r.String()
 }
 
 func Errorf(format string, args ...interface{}) error {
Use strings.Builder instead of string concatenation.

 #lint
