Updated error handling in the example command tool.
Some checks failed
CI / test (push) Failing after 16s
Some checks failed
CI / test (push) Failing after 16s
This commit is contained in:
@@ -36,6 +36,16 @@ jobs:
|
|||||||
run: go build -o ./bin/triplex-example ./cmd/triplex-example
|
run: go build -o ./bin/triplex-example ./cmd/triplex-example
|
||||||
|
|
||||||
- name: Run example
|
- name: Run example
|
||||||
run: ./bin/triplex-example && ./bin/triplex-example --complete ABC-1234-D && echo "Example ran successfully"
|
run: |
|
||||||
|
set +e
|
||||||
|
./bin/triplex-example
|
||||||
|
rc1=$?
|
||||||
|
./bin/triplex-example --complete ABC-1234-D
|
||||||
|
rc2=$?
|
||||||
|
if [ $rc1 -ne 0 ] || [ $rc2 -ne 0 ]; then
|
||||||
|
echo "Example failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Example ran successfully"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"git.hoiting.org/micha/triplex/serial"
|
"git.hoiting.org/micha/triplex/serial"
|
||||||
)
|
)
|
||||||
@@ -37,12 +38,12 @@ func main() {
|
|||||||
full, idx, err := serial.CompleteCode(*complete)
|
full, idx, err := serial.CompleteCode(*complete)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("complete error:", err)
|
fmt.Println("complete error:", err)
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("code:", full)
|
fmt.Println("code:", full)
|
||||||
fmt.Println("idx:", idx)
|
fmt.Println("idx:", idx)
|
||||||
return
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := serial.RandomCodeOptions{
|
opts := serial.RandomCodeOptions{
|
||||||
@@ -59,14 +60,14 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, serial.ErrRandomSourceFailed) {
|
if errors.Is(err, serial.ErrRandomSourceFailed) {
|
||||||
fmt.Println("random source failed")
|
fmt.Println("random source failed")
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if errors.Is(err, serial.ErrNoAvailableIndex) {
|
if errors.Is(err, serial.ErrNoAvailableIndex) {
|
||||||
fmt.Println("no available index found")
|
fmt.Println("no available index found")
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Println("unexpected error:", err)
|
fmt.Println("unexpected error:", err)
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("code:", code)
|
fmt.Println("code:", code)
|
||||||
|
|||||||
Reference in New Issue
Block a user