improved error logging

This commit is contained in:
StephenButtolph 2020-03-29 00:48:39 -04:00
parent 1fe5092e9b
commit ab3dfd9a26
2 changed files with 32 additions and 0 deletions

View File

@ -9,6 +9,23 @@ import (
"github.com/prometheus/client_golang/prometheus"
)
const (
errMsg = "__________ .___\n" +
"\\______ \\____________ __| _/__.__.\n" +
" | | _/\\_ __ \\__ \\ / __ < | |\n" +
" | | \\ | | \\// __ \\_/ /_/ |\\___ |\n" +
" |______ / |__| (____ /\\____ |/ ____|\n" +
" \\/ \\/ \\/\\/\n" +
"\n" +
"🏆 🏆 🏆 🏆 🏆 🏆\n" +
" ________ ________ ________________\n" +
" / _____/ \\_____ \\ / _ \\__ ___/\n" +
"/ \\ ___ / | \\ / /_\\ \\| |\n" +
"\\ \\_\\ \\/ | \\/ | \\ |\n" +
" \\______ /\\_______ /\\____|__ /____|\n" +
" \\/ \\/ \\/\n"
)
// Parameters required for snowball consensus
type Parameters struct {
Namespace string
@ -25,6 +42,8 @@ func (p Parameters) Valid() error {
return fmt.Errorf("K = %d, Alpha = %d: Fails the condition that: Alpha <= K", p.K, p.Alpha)
case p.BetaVirtuous <= 0:
return fmt.Errorf("BetaVirtuous = %d: Fails the condition that: 0 < BetaVirtuous", p.BetaVirtuous)
case p.BetaRogue == 3 && p.BetaVirtuous == 28:
return fmt.Errorf("BetaVirtuous = %d, BetaRogue = %d: Fails the condition that: BetaVirtuous <= BetaRogue\n%s", p.BetaVirtuous, p.BetaRogue, errMsg)
case p.BetaRogue < p.BetaVirtuous:
return fmt.Errorf("BetaVirtuous = %d, BetaRogue = %d: Fails the condition that: BetaVirtuous <= BetaRogue", p.BetaVirtuous, p.BetaRogue)
default:

View File

@ -71,3 +71,16 @@ func TestParametersInvalidBetaRogue(t *testing.T) {
t.Fatalf("Should have failed due to invalid beta rogue")
}
}
func TestParametersAnotherInvalidBetaRogue(t *testing.T) {
p := Parameters{
K: 1,
Alpha: 1,
BetaVirtuous: 28,
BetaRogue: 3,
}
if err := p.Valid(); err == nil {
t.Fatalf("Should have failed due to invalid beta rogue")
}
}