docset-sfdc/SFDashC/errors.go

37 lines
864 B
Go
Raw Normal View History

2016-02-10 20:08:26 +00:00
package main
import (
"errors"
2016-02-10 20:08:26 +00:00
"fmt"
"log"
2016-02-10 20:08:26 +00:00
)
// NewCustomError creates a custom error using a string as the message
func NewCustomError(message string) error {
return errors.New(message)
2016-02-10 20:08:26 +00:00
}
// NewFormatedError creates a new error using Sprintf
func NewFormatedError(format string, a ...interface{}) error {
return NewCustomError(fmt.Sprintf(format, a...))
}
// NewTypeNotFoundError returns an error for a TOCEntry with an unknown type
func NewTypeNotFoundError(entry TOCEntry) error {
2017-07-12 17:35:51 +00:00
return NewFormatedError("Type not found: %s %s", entry.Text, entry.ID)
2016-02-10 20:08:26 +00:00
}
// ExitIfError is a helper function for terminating if an error is not nil
func ExitIfError(err error) {
if err != nil {
log.Fatal(err)
2016-02-10 20:08:26 +00:00
}
}
// WarnIfError is a helper function for terminating if an error is not nil
func WarnIfError(err error) {
if err != nil {
LogDebug(err.Error())
2016-02-10 20:08:26 +00:00
}
}