mirror of
https://github.com/kovetskiy/mark.git
synced 2026-05-03 22:12:35 +00:00
add code & testing files for continue-on-error flag
- add continue-on-error flag as a command line option
- if set, doesnt exit on error and continues
processing other files that were passed in
- add fatalErrorHandler to handle fatal errors
- if continue-on-error flag is set, does not exit
- add temporary tests for continue-on-error flag
- add tests in batch-tests subdirectory
This commit is contained in:
35
error_handler.go
Normal file
35
error_handler.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/reconquest/pkg/log"
|
||||
)
|
||||
|
||||
type FatalErrorHandler struct {
|
||||
ContinueOnError bool
|
||||
}
|
||||
|
||||
func NewErrorHandler(continueOnError bool) *FatalErrorHandler {
|
||||
return &FatalErrorHandler{
|
||||
ContinueOnError: continueOnError,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *FatalErrorHandler) Handle(err error, format string, args ...interface{}) {
|
||||
errorMesage := fmt.Sprintf(format, args...)
|
||||
|
||||
if err == nil {
|
||||
if h.ContinueOnError {
|
||||
log.Error(errorMesage)
|
||||
return
|
||||
}
|
||||
log.Fatal(errorMesage)
|
||||
}
|
||||
|
||||
if h.ContinueOnError {
|
||||
log.Errorf(err, errorMesage)
|
||||
return
|
||||
}
|
||||
log.Fatalf(err, errorMesage)
|
||||
}
|
||||
Reference in New Issue
Block a user