-
Notifications
You must be signed in to change notification settings - Fork 14
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
Plugin State Fixes #408
Plugin State Fixes #408
Conversation
This is a clearer error message format indicating why a socket gets closed.
The tracked error object must be `unknown` and then normalized to Error on the way out of the Socket interface. We do proper type checking on the way out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a few things.
const err = error ?? new Error('Socket closed without error') | ||
log.warn(`onSocketClose with server ${uri}: ${err.message}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is never valid to access error.message
unless we first determine that the error is instanceof Error
. Your handleError
signature up above is wrong, since it should be e: unknown
for the parameter type, and then follow the TypeScript squiggles until you've handled all the cases.
It might make sense to rename let error: Error | undefined
to let errorMessage: string | undefined
, and then handleError
would have code like errorMessage = e instanceof Error ? e.message : String(e)
. Then onSocketClose
wouldn't need to call new Error
, since we are dealing with plain strings now.
Edit: Oh, derp. You end up doing something similar over the next few commits. I still think you should do the string
thing, and maybe smoosh the error-handling commits together into one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think keeping the internal state as an unknown
time is useful for debugging what gets thrown by a breakpoint in onSocketClose
. Making onSocketClose
the top level handler of the thrown thing will make it easier to figure out what weird thing happens at a lower level. For example, if we see '[object Object]'
errors, then we know some weird object is thrown that cannot be converted to a string. And we can debug it by going to this one place in onSocketClose
to figure out what the object is, instead of trying to search for where the throw occurred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense.
src/common/plugin/PluginState.ts
Outdated
@@ -222,11 +229,11 @@ export function makePluginState(settings: PluginStateSettings): PluginState { | |||
}, | |||
|
|||
async updateServers(settings: UtxoUserSettings): Promise<void> { | |||
if (settings === userSettings) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we added this, and then removed it? Maybe squash the commits to avoid the detour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was relevant for the previous change but not for this one. This was one of the reason why I wanted to perhaps have a second PR for these changes since this is really a bug fix on top of the other fix...
I can actually remove the previous line since it's just an early exit/optimization on the previous fix. This would make the PR more cohesive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the last commit change a little by effect of this: 1f3e346#diff-e333c8da8576d31b705ec8d0d92bea632b797f90b76f50b2c961371dd8570b2fR233
I move the constant closer to its place of use.
9deae2b
to
1f3e346
Compare
This will be saved and loaded to/from disk so that during initialization we have accurate `enableCustomServers` state.
By relying on `serverCache` exclusively for our most up-to-date state when calling `refreshServers` we can ensure that our initial load time and subsequent calls are using the correct state for the wallet. This fixes a race condition during initial load time: `userSettings` state was the set to `defaultSettings`. Now that we persists the last user's settings in the `serverCache` under the `'customServers'` key, we can use that instead. We can eliminate the need for a `userSettings` instance variable by using a parameter to pass the new customer servers when invoking `refreshServers`. It never made sense to rely on instance variables, or properties, to pass state around. This new approach is the correct way to manage state.
1f3e346
to
98dd3a5
Compare
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneDescription
none