Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling is buggy/badly documented #109

Open
xouillet opened this issue Apr 28, 2024 · 2 comments
Open

Error handling is buggy/badly documented #109

xouillet opened this issue Apr 28, 2024 · 2 comments

Comments

@xouillet
Copy link

Hi,

I'm trying to understand how error handling is supposed to work for a basic function such as midi.open_port.
Documentation is quite evasive and say that exception should be raised, but it doesn't.

For example the following code:

  libremidi::observer obs;
  auto inputs = obs.get_input_ports();
  libremidi::midi_in midi{
    libremidi::input_configuration{.on_message = midi_cb}
  };
  std::cout << "Trying to open port " << 1 << std::endl;
  midi.open_port(inputs[1]);

No exception is thrown if inputs[1] doesn't exists.

 midi.open_port(inputs[1]).throw_exception()

Throws an exception every time, even if the open succeed.

For now, I'm using (hacky ?)

  if (midi.open_port(inputs[1]) != stdx::error()) {
    throw std::runtime_error("Unable to open midi port");
  }

I don't know if it's the right way to do it, if so it would be nice to have it documented.

Thanks

@jcelerier
Copy link
Member

Hello !
Are you using an official release or the latest master ? Exception handling changed in current master (and has pretty much been removed) - now the handling is done through error propagation with https://github.com/charles-salvia/std_error to enable the library to work in more environments (a future goal is having it work on OS-less embedded platforms and that's a preliminary step).

What's missing is certainly [[nodiscard]] annotations and a documentation update to indicate to the user that the error has to be handled - but over 10-ish years of working with this, the exception handling of the library has caused me much more problems than it solved.

@xouillet
Copy link
Author

Hi,

Thanks for your response.

Yes, I'm using the current master. I now understand the external std::error implementation. I will now assume that the correct way to check a return code is the one I provided, for some reason the boolean cast of a stdx::error doesn't work so we have to check using a comparison to stdx:error()...

A documentation update would be nice indeed :)

Thanks

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

No branches or pull requests

2 participants