diff --git a/decode.go b/decode.go index 9c9d8be..734041a 100644 --- a/decode.go +++ b/decode.go @@ -50,7 +50,7 @@ var decode = &cli.Command{ decodeResult.HexResult.PrivateKey = hex.EncodeToString(b) decodeResult.HexResult.PublicKey = hex.EncodeToString(b) } else { - lineProcessingError(ctx, "hex string with invalid number of bytes: %d", len(b)) + ctx = lineProcessingError(ctx, "hex string with invalid number of bytes: %d", len(b)) continue } } else if evp := sdk.InputToEventPointer(input); evp != nil { @@ -64,7 +64,7 @@ var decode = &cli.Command{ decodeResult.PrivateKey.PrivateKey = value.(string) decodeResult.PrivateKey.PublicKey, _ = nostr.GetPublicKey(value.(string)) } else { - lineProcessingError(ctx, "couldn't decode input '%s': %s", input, err) + ctx = lineProcessingError(ctx, "couldn't decode input '%s': %s", input, err) continue } diff --git a/encode.go b/encode.go index 4eaf3ac..8e86e90 100644 --- a/encode.go +++ b/encode.go @@ -32,7 +32,7 @@ var encode = &cli.Command{ Action: func(ctx context.Context, c *cli.Command) error { for target := range getStdinLinesOrArguments(c.Args()) { if ok := nostr.IsValidPublicKey(target); !ok { - lineProcessingError(ctx, "invalid public key: %s", target) + ctx = lineProcessingError(ctx, "invalid public key: %s", target) continue } @@ -53,7 +53,7 @@ var encode = &cli.Command{ Action: func(ctx context.Context, c *cli.Command) error { for target := range getStdinLinesOrArguments(c.Args()) { if ok := nostr.IsValid32ByteHex(target); !ok { - lineProcessingError(ctx, "invalid private key: %s", target) + ctx = lineProcessingError(ctx, "invalid private key: %s", target) continue } @@ -81,7 +81,7 @@ var encode = &cli.Command{ Action: func(ctx context.Context, c *cli.Command) error { for target := range getStdinLinesOrArguments(c.Args()) { if ok := nostr.IsValid32ByteHex(target); !ok { - lineProcessingError(ctx, "invalid public key: %s", target) + ctx = lineProcessingError(ctx, "invalid public key: %s", target) continue } @@ -119,7 +119,7 @@ var encode = &cli.Command{ Action: func(ctx context.Context, c *cli.Command) error { for target := range getStdinLinesOrArguments(c.Args()) { if ok := nostr.IsValid32ByteHex(target); !ok { - lineProcessingError(ctx, "invalid event id: %s", target) + ctx = lineProcessingError(ctx, "invalid event id: %s", target) continue } @@ -189,7 +189,7 @@ var encode = &cli.Command{ if d == "" { d = c.String("identifier") if d == "" { - lineProcessingError(ctx, "\"d\" tag identifier can't be empty") + ctx = lineProcessingError(ctx, "\"d\" tag identifier can't be empty") continue } } @@ -216,7 +216,7 @@ var encode = &cli.Command{ Action: func(ctx context.Context, c *cli.Command) error { for target := range getStdinLinesOrArguments(c.Args()) { if ok := nostr.IsValid32ByteHex(target); !ok { - lineProcessingError(ctx, "invalid event id: %s", target) + ctx = lineProcessingError(ctx, "invalid event id: %s", target) continue } diff --git a/event.go b/event.go index 9fc3f4d..c1b3bfa 100644 --- a/event.go +++ b/event.go @@ -176,7 +176,7 @@ example: if stdinEvent != "" { if err := easyjson.Unmarshal([]byte(stdinEvent), &evt); err != nil { - lineProcessingError(ctx, "invalid event received from stdin: %s", err) + ctx = lineProcessingError(ctx, "invalid event received from stdin: %s", err) continue } kindWasSupplied = strings.Contains(stdinEvent, `"kind"`) diff --git a/fetch.go b/fetch.go index 0a59108..b71fd9a 100644 --- a/fetch.go +++ b/fetch.go @@ -38,7 +38,7 @@ var fetch = &cli.Command{ prefix, value, err := nip19.Decode(code) if err != nil { - lineProcessingError(ctx, "failed to decode: %s", err) + ctx = lineProcessingError(ctx, "failed to decode: %s", err) continue } @@ -88,7 +88,7 @@ var fetch = &cli.Command{ } if len(relays) == 0 { - lineProcessingError(ctx, "no relay hints found") + ctx = lineProcessingError(ctx, "no relay hints found") continue } diff --git a/helpers.go b/helpers.go index 673165a..52da7d7 100644 --- a/helpers.go +++ b/helpers.go @@ -169,9 +169,9 @@ relayLoop: return pool, relays } -func lineProcessingError(ctx context.Context, msg string, args ...any) { - ctx = context.WithValue(ctx, LINE_PROCESSING_ERROR, true) +func lineProcessingError(ctx context.Context, msg string, args ...any) context.Context { log(msg+"\n", args...) + return context.WithValue(ctx, LINE_PROCESSING_ERROR, true) } func exitIfLineProcessingError(ctx context.Context) { diff --git a/key.go b/key.go index 0bb12cf..f885b14 100644 --- a/key.go +++ b/key.go @@ -50,7 +50,7 @@ var public = &cli.Command{ for sec := range getSecretKeysFromStdinLinesOrSlice(ctx, c, c.Args().Slice()) { pubkey, err := nostr.GetPublicKey(sec) if err != nil { - lineProcessingError(ctx, "failed to derive public key: %s", err) + ctx = lineProcessingError(ctx, "failed to derive public key: %s", err) continue } stdout(pubkey) @@ -88,7 +88,7 @@ var encrypt = &cli.Command{ for sec := range getSecretKeysFromStdinLinesOrSlice(ctx, c, keys) { ncryptsec, err := nip49.Encrypt(sec, password, uint8(c.Int("logn")), 0x02) if err != nil { - lineProcessingError(ctx, "failed to encrypt: %s", err) + ctx = lineProcessingError(ctx, "failed to encrypt: %s", err) continue } stdout(ncryptsec) @@ -133,7 +133,7 @@ var decrypt = &cli.Command{ for ncryptsec := range getStdinLinesOrArgumentsFromSlice([]string{ncryptsec}) { sec, err := nip49.Decrypt(ncryptsec, password) if err != nil { - lineProcessingError(ctx, "failed to decrypt: %s", err) + ctx = lineProcessingError(ctx, "failed to decrypt: %s", err) continue } nsec, _ := nip19.EncodePrivateKey(sec) @@ -264,13 +264,13 @@ func getSecretKeysFromStdinLinesOrSlice(ctx context.Context, c *cli.Command, key if strings.HasPrefix(sec, "nsec1") { _, data, err := nip19.Decode(sec) if err != nil { - lineProcessingError(ctx, "invalid nsec code: %s", err) + ctx = lineProcessingError(ctx, "invalid nsec code: %s", err) continue } sec = data.(string) } if !nostr.IsValid32ByteHex(sec) { - lineProcessingError(ctx, "invalid hex key") + ctx = lineProcessingError(ctx, "invalid hex key") continue } ch <- sec diff --git a/relay.go b/relay.go index d0e9e3a..5e54145 100644 --- a/relay.go +++ b/relay.go @@ -23,7 +23,7 @@ var relay = &cli.Command{ info, err := nip11.Fetch(ctx, url) if err != nil { - lineProcessingError(ctx, "failed to fetch '%s' information document: %w", url, err) + ctx = lineProcessingError(ctx, "failed to fetch '%s' information document: %w", url, err) continue } diff --git a/req.go b/req.go index b987866..1f542ad 100644 --- a/req.go +++ b/req.go @@ -182,7 +182,7 @@ example: filter := nostr.Filter{} if stdinFilter != "" { if err := easyjson.Unmarshal([]byte(stdinFilter), &filter); err != nil { - lineProcessingError(ctx, "invalid filter '%s' received from stdin: %s", stdinFilter, err) + ctx = lineProcessingError(ctx, "invalid filter '%s' received from stdin: %s", stdinFilter, err) continue } } diff --git a/verify.go b/verify.go index 1857fd0..7860b8d 100644 --- a/verify.go +++ b/verify.go @@ -20,18 +20,18 @@ it outputs nothing if the verification is successful.`, evt := nostr.Event{} if stdinEvent != "" { if err := json.Unmarshal([]byte(stdinEvent), &evt); err != nil { - lineProcessingError(ctx, "invalid event: %s", err) + ctx = lineProcessingError(ctx, "invalid event: %s", err) continue } } if evt.GetID() != evt.ID { - lineProcessingError(ctx, "invalid .id, expected %s, got %s", evt.GetID(), evt.ID) + ctx = lineProcessingError(ctx, "invalid .id, expected %s, got %s", evt.GetID(), evt.ID) continue } if ok, err := evt.CheckSignature(); !ok { - lineProcessingError(ctx, "invalid signature: %s", err) + ctx = lineProcessingError(ctx, "invalid signature: %s", err) continue } }