Skip to content

Conversation

m-2k
Copy link

@m-2k m-2k commented Aug 10, 2025

Changes:

  • version: 2.0.0
  • internal JSON encoder/decoder from EEP 68;
  • opaque variable for handlers;
  • the "map" style function has been changed to a "mapfold" style function to handle opaque data;
  • logger from OTP 21.0 is used.

Closes issues #5, #7, #10

@m-2k m-2k force-pushed the master branch 2 times, most recently from 6753241 to 934fc55 Compare August 10, 2025 13:50
@m-2k
Copy link
Author

m-2k commented Aug 12, 2025

@zuiderkwast do you plan to change anything in Ur repository in the future and will U consider this pull request? Thx.

@zuiderkwast
Copy link
Owner

Hi @m-2k! It's a great update!

I haven't been maintaining this project very actively. As you can see, it has very few changes over the last 10 years.

If I read this PR correctly, I can just merge it and set a 2.0.0 tag, right? Nothing more is required? Then it may be good for another 10 years.

Copy link
Owner

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

This is a complete rewrite of the whole library, not only the API. It is quite large and I'm not using this project anymore. I'm thinking maybe it's better that I deprecate or archive this project and link to your fork instead. What do you think?

Apart from comments below, I noticed the documentation was deleted and there is no new documentation, only examples.

support concurrent processing of the requests in a batch,
* handles rpc calls and notifications,
* supports named and unnamed parameters,
support concurrent processing of the requests in a batch or collecting statistics;
Copy link
Owner

Choose a reason for hiding this comment

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

I see you changed from lists:map/3 to lists:mapfoldl/3.

To process requests in parallel, you could replace lists:map/3 with a function that spawns a process for each request, waits for all of them to complete, then returns the list of replies.

How would you do that with the mapfoldl API?

Also, how would you collect statistics and get them out?

Comment on lines +176 to +180
response_error({Code, Reason, Data}) when is_integer(Code) andalso (Code < -32768 orelse Code > -32000) -> #{
code => Code,
message => response_error_message(Reason),
data => Data
};
Copy link
Owner

Choose a reason for hiding this comment

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

This is not the common style in Erlang (although it's normal in languages like C with braces.)

In Erlang, the } or ], end, etc. are straight below or to the right of their opening counterpart, not to the left of it.

I'd prefer to use the OTP style, including 4 spaces indentation, like this:

Suggested change
response_error({Code, Reason, Data}) when is_integer(Code) andalso (Code < -32768 orelse Code > -32000) -> #{
code => Code,
message => response_error_message(Reason),
data => Data
};
response_error({Code, Reason, Data}) when is_integer(Code) andalso (Code < -32768 orelse Code > -32000) ->
#{
code => Code,
message => response_error_message(Reason),
data => Data
};

Term ->
do_handle_term(Term, Handler, OpaqueCtxIn, MapFoldFun)
catch Class1:Reason1 ->
?LOG_WARNING("Failed to decode request in JSON format: ~tp ~tp", [Class1, Reason1]),
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think we should log a warning here. If an untrusted user, such as remote client over the network, can send requests, they can flood the log.

If the request is malformed (syntax error, etc.) it's a client error, not a server error. It should just be reported back to the client.

Comment on lines +122 to +124
request(#{method := Mtd} = RequestSpec) ->
Method = case RequestSpec of
#{module := Mod} -> <<(atom_to_binary(Mod))/binary, $:, (atom_to_binary(Mtd))/binary>>;
Copy link
Owner

Choose a reason for hiding this comment

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

This "module" is an undocumented extension to JSON-RPC. Why not just require the client to use "mod:func" as the method? I would prefer to avoid ad-hoc extensions and just stick to the standard.

Comment on lines -114 to -117
* `throw(method_not_found)` is reported as "Method not found" (-32601)
* `throw(invalid_params)` is reported as "Invalid params" (-32602)
* `throw(internal_error)` is reported as "Internal error" (-32603)
* `throw(server_error)` is reported as "Server error" (-32000)
Copy link
Owner

Choose a reason for hiding this comment

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

Returning RPC errors from the handler using throw is not supported anymore? Why not?

@zuiderkwast
Copy link
Owner

I changed the About text for this repo to link to your fork instead. Let me know what you think.

The next step is that I will archive this repo, if you agree.

@m-2k
Copy link
Author

m-2k commented Aug 15, 2025

This is a complete rewrite of the whole library, not only the API. It is quite large and I'm not using this project anymore. I'm thinking maybe it's better that I deprecate or archive this project and link to your fork instead. What do you think?

Yes, I’ll be able to maintain my fork and accept changes in the future.


Interesting remarks.
Some I expected, some make me think.
In any case, the answer is roughly this: I haven’t had much time to make things neat; I needed a working solution for my project at now. Once I have the time, I’ll think over each point from your comments.

So far, the only additional work done on the repository has been adding test coverage and a consistent README.md, which is what prompted the above comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants