Skip to content

Commit

Permalink
Handle errors from printLineAndFlush function
Browse files Browse the repository at this point in the history
Updated the printLineAndFlush function to return an error instead of terminating the program. Modified the main function to handle the error appropriately by logging the error and exiting when printLineAndFlush fails.
  • Loading branch information
rolandgroen committed Nov 11, 2024
1 parent b2944f5 commit c3c8f13
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ func main() {
fmt.Println(err)
os.Exit(-1)
}
println(jwt)
err = printLineAndFlush(jwt)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
case "test-cert <uzi> <ura> <agb>", "test-cert <uzi> <ura> <agb> <subject_did>":
// Format is 2.16.528.1.1007.99.2110-1-900030787-S-90000380-00.000-11223344
// <OID CA>-<versie-nr>-<UZI-nr>-<pastype>-<Abonnee-nr>-<rol>-<AGB-code>
Expand Down Expand Up @@ -94,26 +98,27 @@ func main() {
fmt.Println(err)
os.Exit(-1)
}
printLineAndFlush(jwt)
err = printLineAndFlush(jwt)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
default:
fmt.Println("Unknown command")
os.Exit(-1)
}
}

// printLineAndFlush writes a JWT (JSON Web Token) to the standard output and flushes the buffered writer.
func printLineAndFlush(jwt string) {
func printLineAndFlush(jwt string) error {
f := bufio.NewWriter(os.Stdout)
// Make sure to flush
defer func(f *bufio.Writer) {
_ = f.Flush()
}(f)
// Write the JWT
_, err := f.WriteString(jwt + "\n")
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
return err
}

func issueVc(vc VC) (string, error) {
Expand Down

0 comments on commit c3c8f13

Please sign in to comment.