iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
582 stars 210 forks source link

No errors/warnings for IpcHandler not registered and duplicate command ids. #6787

Open bishalatbentley opened 1 month ago

bishalatbentley commented 1 month ago

Is your feature request related to a problem? Please describe. We didn't get any errors or warnings in the console in the below two cases:

  1. If someone forgets to register IpcHandler.
  2. If there is duplicate command id. (Error is there but not very clear as what to do)

Error/warning in the console could immediately tell the developer what to do to fix the problem. And sometimes it might take a lot of time to figure out the issue for someone new.

Describe the solution you'd like Logging errors in the console for the two cases:

  1. If someone forgets to register IpcHandler.
  2. If there is duplicate command id. (Error is there but not very clear as what to do)

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

pmconne commented 1 month ago

Show code that illustrates your problems.

bishalatbentley commented 1 month ago

Suppose I have an IpcHandler like this:

 class MyHandler extends IpcHandler implements MyInterface

If I forget to register it, I was expecting it should give some error in the console.

Similarly, for EditCommands, if I use same command ID in two different commands, I was expecting it will give relevant error something like "Duplicate command Id MyCommandId used"

class MyCommand extends EditCommand implements MyCommandIpc {
  public static override commandId =  "MyCommandId";
class SomeCommand extends EditCommand implements SomeCommandIpc {
  public static override commandId =  "MyCommandId";
pmconne commented 1 month ago

When, specifically, would you expect to see each of these errors? In the case of the duplicate command, you said "Error is there but not very clear as what to do". What error specifically and when does it occur?

bishalatbentley commented 1 month ago

IpcHandler

I was using IpcHandler in a studio app. I was calling the backend method (member of IpcHandler) from frontend via ipc which should in turn call the actual backend method. And, it was not calling the backend method and I was clueless what I am missing. So, maybe, at that time, it should tell that MyIpcHandler is not registered and I should register it first. Other option could be showing the error when the app starts but I'm not sure if that's possible and even a good idea.

Duplicate command id

The error was something like caller.whateverMethodIWasTryingToCall is not a function. One command was taking precedence over the other, and the backend endpoints weren't being hit. As this error was experienced by one of my team members but I think the error comes when we call the methods from FE which are part of commands.

pmconne commented 1 month ago

Thanks. Your best chance for getting a fix for this in the near term is to submit a PR.