-
Notifications
You must be signed in to change notification settings - Fork 52
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
[RFC] We need a better error system #159
Comments
Thanks for the RFC, it's a very good proposal. Could you be able to provide 3 of the best examples that you could find in other open source projects, and points out which part do you think they are the best? I believe we need more 砖 to study first, then we will be able to discuss deeper based on them. |
I could try to find some good examples. And will post it in the issue. In the mean time, how about |
After thinking this RFC for the past 12 months, I believe that we can move forward to continue discussing how to implement it because we will have some huge improvements for the Wechaty recently after we landing the Multi-language Wechaty. @windmemory Would you like to share some more thoughts from your experiences in the past year? I believe it would be a great help for us to understand what is the best design of our Error system. |
From the previous experience, I think there are two key properties needs to be reported when an error happened. They are:
Error typeI think we can achieve this feature in two ways
RecoverableThis can be solved in similar ways as above.
Other topic needs to be considered and discussed
|
Discussion Draftenum WechatyErrorType {
UNKNOWN = 0,
NO_PAYLOAD = 1,
}
puppet.on('error', data => {
const e = new WechatyError(data)
})
class WechatyError extends Error {
public static from (data: grpcError) {
payload = JSON.parse(data)
const e = new this(payload)
return e
}
public to() {
return {
message: this.message,
name: this.name,
stack: this.stack,
type: this.type,
}
}
private type: WechatyErrorType
private constructor (
payload: any
) {
this.type = WechatyErrorType[payload.type] ?? WechatyErrorType.UNKNOWN
}
} Google API Design Principle: Errors |
* create PayloadCache class * init mixins * add mixin docs * code clean * change protected to jsdoc (#155) * add CacheMixin & WatchdogMin with PuppetSkelton * add CacheMixin & WatchdogMin with PuppetSkelton * clean * follow mixin design (#156) * Create PuppetError classes (#159) * split all code into mixins * fix memory * fix * fix memory * 0.49.4 * clean * 0.49.5 * rename PuppetError -> GError * rename PuppetError -> GError * 0.49.6 * clean code * 0.49.7
We have implemented the first version of a gRPC and ECMA compatible error class: Learn more at https://github.com/wechaty/puppet/blob/main/src/gerror/gerror.ts |
#2275) * add WechatyInterface & WechatyConstructor, as well as all User Class -es * Interface all APIs * 0.77.6 * change all Wechaty classes to interfaces * 0.77.7 * move some of the user class to be Interface * 0.77.8 * refactoring all user class to interfaces * 0.77.9 * clean up * 0.77.10 * add validation util * 0.77.11 * use mixin to add valid api to all user classes * 0.77.12 * only emit GError for error event in Wechaty (wechaty/puppet#159) * 1. Add `wechaty.emitError(e: unknown)` to convert all errors to GError 2. Add `isTemplateStringArray` type guard (with unit test) 3. Add `Sleeper` user class to just sleep a while when it is being `say`-ed 4. Add `impl.*` export for user class implements 5. refactory `say()` code to keep DRY 6. code clean * 0.77.13 * code clean * 0.77.14 * add WechatyBuilder factory class * add WechatyBuilder factory class * 0.77.15 * clean * 0.77.16
Is your feature request related to a problem? Please describe.
Recently we observed more and more limitation pushed out by WeChat. In some cases, connection to WeChat server got kicked out. It would be better that we emit these cases as errors so developers could handle them properly.
Currently all the error messages emitted is an
Error
instance, only one message on it, so it is really hard to set a solid error type for the error. So here is this issue, I would like to bring this issue up and talk about the design forWechatyError
or something else :PDescribe the solution you'd like
We could have a parent error type as
WechatyError
, thenPuppetError
extends the parent, then each puppet has its own error class.How about this design:
Or we could make this parent error as an abstract class, then all the other errors extends this one.
Describe alternatives you've considered
Haven't considered any alternatives...
Additional context
I've implemented one temporary solution in
wechaty-puppet-padpro
, but that's just a test, you could check it here:wechaty/wechaty-puppet-padpro@47d8de1
Here is a small piece of code that how I use it:
To be honest, this is ugly, but just treat this as 【抛砖引玉】(don't know how to translate this :P)
Let's make
wechaty
better and better.[enhancement]
The text was updated successfully, but these errors were encountered: