replace log.Fatal with cobra.CheckErr

This commit is contained in:
filifa
2025-08-27 21:33:44 -04:00
parent 51e1a97c43
commit 65c8ab4057
5 changed files with 14 additions and 18 deletions

View File

@@ -18,7 +18,6 @@ package cmd
import (
"fmt"
"log"
"math/big"
"github.com/spf13/cobra"
@@ -30,7 +29,7 @@ var moduli []string
func crt(cmd *cobra.Command, args []string) {
if len(remainders) != len(moduli) {
log.Fatal("number of remainders and moduli do not match")
cobra.CheckErr("number of remainders and moduli do not match")
}
ns := make([]*big.Int, len(moduli))
@@ -39,18 +38,19 @@ func crt(cmd *cobra.Command, args []string) {
var ok bool
ns[i], ok = new(big.Int).SetString(moduli[i], 10)
if !ok {
log.Fatal("invalid input " + moduli[i])
cobra.CheckErr("invalid input " + moduli[i])
}
rs[i], ok = new(big.Int).SetString(remainders[i], 10)
if !ok {
log.Fatal("invalid input " + remainders[i])
cobra.CheckErr("invalid input " + remainders[i])
}
}
// TODO: support non-pairwise coprime moduli
if !lib.ArePairwiseCoprime(ns) {
log.Fatalf("moduli %v are not pairwise coprime", moduli)
err := fmt.Errorf("moduli %v are not pairwise coprime", moduli)
cobra.CheckErr(err)
}
x, N := lib.CRTSolution(rs, ns)