csctl/internal/custom.go

32 lines
1.2 KiB
Go
Raw Permalink Normal View History

2020-12-18 20:25:22 -05:00
package internal
import (
2020-12-25 17:20:30 -05:00
"errors"
2020-12-18 20:25:22 -05:00
"fmt"
"github.com/kataras/golog"
"os"
"os/user"
"time"
)
2020-12-25 17:20:30 -05:00
func Error(err error, msg string) error {
2020-12-18 20:25:22 -05:00
currentUser, _ := user.Current()
path := fmt.Sprintf("%s/.csctl.err.log", currentUser.HomeDir)
file, errf := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)
if errf != nil {
golog.Error("An error has occurred while handling another error. Please alert a technician immediately.")
fmt.Printf("==ERROR==\nOccurred at: %s || Message: %s\n\n%s\n\n\n", time.Now().String(), "nil", errf.Error())
panic(errf)
}
defer file.Close()
contents := fmt.Sprintf("==ERROR==\nOccurred at: %s || Message: %s\n\n%s\n\n\n", time.Now().String(), msg, err.Error())
_, errf = file.WriteString(contents)
if errf != nil {
golog.Error("An error has occurred while handling another error. Please alert a technician immediately.")
fmt.Printf("==ERROR==\nOccurred at: %s || Message: %s\n\n%s\n\n\n", time.Now().String(), "nil", errf.Error())
panic(errf)
}
golog.Fatal("An error has occurred while processing the executable. A log file has been created in %s, please alert a Technician and provide the contents of this file if needed.\n", path)
2020-12-25 17:20:30 -05:00
return errors.New(fmt.Sprintf("%s\n\nError Details: %s", msg, err))
2020-12-18 20:25:22 -05:00
}