From ed5a23bce1018105ba6315265f5c65f4d2aa9ca1 Mon Sep 17 00:00:00 2001 From: micha Date: Sat, 21 Feb 2026 04:26:32 +0100 Subject: [PATCH] Updated error handling in the example command tool. --- .gitea/workflows/ci.yml | 10 +++++++--- cmd/triplex-example/main.go | 11 ++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index e59298c..35ce5bd 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -36,6 +36,10 @@ jobs: run: go build -o ./bin/triplex-example ./cmd/triplex-example - name: Run example - run: ./bin/triplex-example && ./bin/triplex-example --complete ABC-1234-D && echo "Example ran successfully" - - + run: | + if ./bin/triplex-example && ./bin/triplex-example --complete ABC-123-D; then + echo "Example ran successfully" + else + echo "Example failed" + exit 1 + fi diff --git a/cmd/triplex-example/main.go b/cmd/triplex-example/main.go index aac91e8..3d85271 100644 --- a/cmd/triplex-example/main.go +++ b/cmd/triplex-example/main.go @@ -8,6 +8,7 @@ import ( "errors" "flag" "fmt" + "os" "git.hoiting.org/micha/triplex/serial" ) @@ -37,12 +38,12 @@ func main() { full, idx, err := serial.CompleteCode(*complete) if err != nil { fmt.Println("complete error:", err) - return + os.Exit(1) } fmt.Println("code:", full) fmt.Println("idx:", idx) - return + os.Exit(0) } opts := serial.RandomCodeOptions{ @@ -59,14 +60,14 @@ func main() { if err != nil { if errors.Is(err, serial.ErrRandomSourceFailed) { fmt.Println("random source failed") - return + os.Exit(1) } if errors.Is(err, serial.ErrNoAvailableIndex) { fmt.Println("no available index found") - return + os.Exit(1) } fmt.Println("unexpected error:", err) - return + os.Exit(1) } fmt.Println("code:", code)