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

Make EResult (or the full response) accessible in SteamAuthenticatorError. #357

Open
luckydonald opened this issue Sep 15, 2021 · 3 comments

Comments

@luckydonald
Copy link

luckydonald commented Sep 15, 2021

So current situation is that stuff like SteamAuthenticator(…).add() can cause SteamAuthenticatorError.

For example,

Traceback (most recent call last):
…
steam.guard.SteamAuthenticatorError: Failed to add authenticator. Error: <EResult.DuplicateRequest: 29>

Now that's a pretty easy to catch that error, telling the user to first have it log off the old instance, hence duplicate.
Just, we can't really distinguish those errors unless we do some ugly string stuff on that returned string.

# "Failed to add authenticator. Error: <EResult.DuplicateRequest: 29>"
if str(e).startswith("Failed to add authenticator. Error: <EResult."):
  error_string = str(e)[45:-1]  # "DuplicateRequest: 29"
  error_label, error_num = error_string.split(": ")
  from steam.enums import EResult
  error_label = EResult[error_label]
  error_num = EResult(int(error_num))
  if error_label == error_num:
    error = error_label
  # end if
  if error == EResult.DuplicateRequest:
    exit('Already have set an authenticator in another app')
  # end if
# end if

This is obviously super prone to issues due to changes there, it would be way better to just include those fields in the exception.

@rossengeorgiev
Copy link
Contributor

rossengeorgiev commented Sep 27, 2021

That's a good point.

steam/steam/guard.py

Lines 469 to 470 in 061ca33

class SteamAuthenticatorError(Exception):
pass

SteamAuthenticatorError should really inherit from steam.exceptions.SteamError. And then any places where it sets the eresult should be passed as parameter. This looks like a straightforward change

@luckydonald
Copy link
Author

I can see if I have time to do a PR

@luckydonald
Copy link
Author

Made one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants