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

feat: subscriptions get passed result questionable #91

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

AuHau
Copy link
Member

@AuHau AuHau commented Oct 31, 2024

Introduces breaking change to API, where subscription handlers now return Result type. Handlers, similarly to now will be called with events wrapped in the Result when new events are detected, but also handlers will be called when some error in the underlying event detection mechanism is detected.

@AuHau AuHau force-pushed the feat/subscriptions-get-passed-result-questionable branch from bf3c197 to 26ed902 Compare October 31, 2024 13:48
Copy link
Contributor

@emizzle emizzle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing necessarily blocking except maybe what's in confirm (echo "What to do now? 😳") 😂 All the rest are suggestions of sorts... and loooots of extra spaces :) So I'll approve now

Readme.md Show resolved Hide resolved
Comment on lines +3 to +8
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you update the CI workflow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because in the way we have it till now the CI gets "double triggered" because of PR and "push". See: https://discord.com/channels/895609329053474826/963349623714504784/1301528920893558855

Comment on lines +4 to +12
SolidityError* = object of EthersError
ContractError* = object of EthersError
SignerError* = object of EthersError
SubscriptionError* = object of EthersError
ProviderError* = object of EthersError
data*: ?seq[byte]

template raiseSignerError*(message: string, parent: ref ProviderError = nil) =
raise newException(SignerError, message, parent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 I don't really feel like these need to be in a "shared" module, unless the errors are shared across modules. Iow, I don't mind that they live in their specific module, eg SignerError in the signer module. Matter of preference maybe.

Comment on lines +114 to +115
onBlock(failure(Block, error.toErr(SubscriptionError)))
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's too many spaces here.

for change in await getChanges(id):
callback(id, success(change))
except CancelledError as e:
raise e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dude

Comment on lines 82 to +90
try:
if not id.isNil and id in subscriptions.callbacks:
subscriptions.callbacks[id].some
try:
return subscriptions.callbacks[id].some
except: discard
else:
SubscriptionCallback.none
return SubscriptionCallback.none
except KeyError:
SubscriptionCallback.none
return SubscriptionCallback.none
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing lines 84-86

What exception was leaking from subscriptions.callbacks[id].some?

By default, SubscriptionCallback.none is returned, so we don't really need line 87-88.

The catching of KeyError is not needed with the try/except since it's caught on 86. If you're going to use try/except discard, then this whole thing can be a bit nicer:

if not id.isNil and id in subscriptions.callbacks:
  try:
    return subscriptions.callbacks[id].some
  except: discard


proc poll(id: JsonNode) {.async: (raises: [CancelledError, SubscriptionError]).} =
without callback =? subscriptions.getCallback(id):
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing

Comment on lines +234 to +235
let wrappedErr = newException(SubscriptionError, "HTTP polling: There was an exception while getting subscription's block: " & e.msg, e)
onBlock(failure(Block, wrappedErr))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 can also do:

Suggested change
let wrappedErr = newException(SubscriptionError, "HTTP polling: There was an exception while getting subscription's block: " & e.msg, e)
onBlock(failure(Block, wrappedErr))
let err = e.toErr(SubscriptionError,
"HTTP polling: There was an exception while getting subscription's block: " & e.msg)
onBlock(failure(Block, err))

Comment on lines +239 to +240
onBlock(failure(Block, error.toErr(SubscriptionError)))
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing

Comment on lines +258 to +259
onLog(failure(Log, error.toErr(SubscriptionError)))
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing, fml

Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com>
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