Updated error handling in the example command tool.
All checks were successful
CI / test (push) Successful in 17s

This commit is contained in:
2026-02-21 04:26:32 +01:00
parent 22ca29b4af
commit 41c78367d3
2 changed files with 10 additions and 6 deletions

View File

@@ -36,6 +36,9 @@ 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: |
./bin/triplex-example && \
./bin/triplex-example --complete ABC-1234-D && \
echo "Example ran successfully" || echo "Example failed"

View File

@@ -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)