Skip to content

Conversation

@tcheeric
Copy link
Owner

Summary

  • replace JsonProcessingException with EventEncodingException across message encoders and decoders
  • surface EventEncodingException from message and tag codecs
  • adjust integration tests for new exception handling

Testing

  • mvn -q verify (fails: Previous attempts to find a Docker environment failed. Will not retry.)

https://chatgpt.com/codex/tasks/task_b_68a812eddc248331a9df050b0ea234ad

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the codebase to use a custom EventEncodingException for all encoding/decoding operations instead of the generic JsonProcessingException. This change provides more specific exception handling for Nostr protocol-related encoding failures and improves error context by wrapping underlying Jackson exceptions with descriptive messages.

Key changes include:

  • Replacing JsonProcessingException with EventEncodingException in method signatures across message classes and codecs
  • Adding try-catch blocks to wrap Jackson exceptions with meaningful error messages
  • Updating integration tests to handle the new exception type

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
BaseMessage.java Updated abstract encode method signature to throw EventEncodingException
IDecoder.java Removed JsonProcessingException from interface, simplifying decoder contract
Multiple message classes Added exception wrapping in encode/decode methods with descriptive error messages
Codec classes Updated to throw EventEncodingException with proper error context
ApiEventIT.java Updated integration test to handle new exception type

} catch (EventEncodingException e) {
throw new IllegalStateException("Failed to encode event", e);
return ENCODER_MAPPER_BLACKBIRD.writeValueAsString(arrayNode);
} catch (JsonProcessingException e) {
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BaseEventEncoder.encode() method now throws EventEncodingException, but this call is not wrapped in a try-catch block. This will cause a compilation error since the encode() method is called within a try block that only catches JsonProcessingException.

Copilot uses AI. Check for mistakes.
} catch (EventEncodingException e) {
throw new IllegalStateException("Failed to encode canonical authentication event", e);
} catch (JsonProcessingException e) {
throw new EventEncodingException("Failed to encode canonical authentication message", e);
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BaseEventEncoder.encode() method now throws EventEncodingException, but this call is not wrapped in a try-catch block. This will cause a compilation error since the encode() method is called within a try block that only catches JsonProcessingException.

Copilot uses AI. Check for mistakes.
ObjectMapper I_DECODER_MAPPER_BLACKBIRD
= JsonMapper.builder().addModule(new BlackbirdModule()).build().configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
T decode(String str) throws JsonProcessingException;
T decode(String str);
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IDecoder interface signature has been changed to not throw any exceptions, but many implementing classes in the codebase now throw EventEncodingException. This creates an inconsistency where implementations cannot declare checked exceptions that aren't in the interface.

Suggested change
T decode(String str);
T decode(String str) throws EventEncodingException;

Copilot uses AI. Check for mistakes.
@tcheeric tcheeric merged commit 88f51c6 into develop Aug 22, 2025
3 of 4 checks passed
@tcheeric tcheeric deleted the codex/replace-jsonprocessingexception-with-eventencodingexception branch August 22, 2025 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants