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

Expose error name for MessageBus.invoke() errors #2

Merged
merged 1 commit into from
Nov 3, 2022

Conversation

elyscape
Copy link

@elyscape elyscape commented Nov 2, 2022

♻️ Current situation

MessageBus.invoke() takes a callback, the first argument of which is the error encountered, if any, and the remaining arguments are the return arguments of the D-Bus method call. Per the D-Bus spec, messages of type ERROR are described as follows:

Error reply. If the first argument exists and is a string, it is an error message.

Additionally, these messages must have an ERROR_NAME header field, which is a string that indicates the type of error they represent.

Currently, if an error occurs, MessageBus.invoke() passes the return arguments, and not the error name, to the callback. The upshot of this is that the callback receives only the user-friendly explanation of what went wrong, not the machine-usable error type.

💡 Proposed solution

This changes the behavior of MessageBus.invoke() to, when an error occurs, invoke the callback passing as the first argument an object that looks like this:

{
  name: "ERROR_NAME",
  message: "what used to be passed in as the first argument"
}

⚙️ Release Notes

  • Breaking change: When an error occurs in MessageBus.invoke() or MessageBus.invokeDbus(), the first argument passed to the callback (err) is now an object containing two keys: name is the D-Bus error name, and message is what previously was passed in as this argument.

➕ Additional Information

See homebridge/HAP-NodeJS#980 (comment)

@elyscape
Copy link
Author

elyscape commented Nov 2, 2022

cc: @Supereg

@Supereg
Copy link
Member

Supereg commented Nov 2, 2022

Update: actually, I had a better idea for this. Don't merge it yet, please.

I had this in my E-Mail. Does this still apply?

@elyscape
Copy link
Author

elyscape commented Nov 2, 2022

Nope, I changed my mind.

@elyscape
Copy link
Author

elyscape commented Nov 3, 2022

That is to say, this is good to go whenever.

@Supereg Supereg merged commit 3c3a7f9 into homebridge:master Nov 3, 2022
@elyscape elyscape deleted the expose-error-name branch November 8, 2022 22:34
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