at_client_sdk icon indicating copy to clipboard operation
at_client_sdk copied to clipboard

`AtClient.get` throws an AtClientException when it should be AtKeyNotFoundException

Open JeremyTubongbanua opened this issue 1 year ago • 14 comments

Describe the bug

AtClient.get is throwing an AtClientException when it should be throwing a AtKeyNotFoundException

Steps to reproduce

  1. Try doing AtClient.get in a try/catch on a public:publickey@
  2. We know that the secondary exists but the public:publickey has not been instantiated yet (since they haven't onboarded yet).
  3. AtClient.get throws an AtClientException

See logs in additional context section.

Expected behavior

AtClient.get throws a AtKeyNotFoundException when the public:publickey@ does not exist.

Screenshots

No response

Smartphones

No response

Were you using an atApplication when the bug was found?

No response

Additional context

The dart code I ran:

```dart
try {
  await atClient.get(publicKey);
  return true;
} catch (e) {
  if(e is AtKeyNotFoundException || e is AtClientException) {
    
    return false;
  }
  rethrow;
}

The error message

AtClientException // the exception that it threw, I used print()
Unhandled exception:
Exception: Internal server exception : Request to remote secondary @noblesnowbaboon at null:null received error response 'AT0015-Exception: public:publickey@noblesnowbaboon does not exist in keystore'
#0      AtClientImpl.get (package:at_client/src/client/at_client_impl.dart:349)
<asynchronous suspension>
#1      atSignIsActivated (package:sshnoports/sshnp_utils.dart:84)
<asynchronous suspension>
#2      SSHNP.init (package:sshnoports/sshnp.dart:180)
<asynchronous suspension>
#3      main (file:///build/repo/bin/sshnp.dart:21)
<asynchronous suspension>

JeremyTubongbanua avatar Jun 27 '23 04:06 JeremyTubongbanua

@JeremyTubongbanua how does an atsign have a secondary without being onboarded? not sure how to tackle this.

Xlin123 avatar Jun 29 '23 18:06 Xlin123

Three stages:

  1. Registration - atSign is registered but not activated - no atServer running
  2. Activation - atServer running
  3. Onboarding - user does cram auth, generates atKeys

gkc avatar Jun 29 '23 18:06 gkc

Ooo, thanks Gary. I didn't know that activation and onboarding were different. That would make sense.

Xlin123 avatar Jun 29 '23 18:06 Xlin123

@Xlin123 to expand on Gary's comment

  1. Registration - you bought the atSign and it's assigned to your email
  2. Activation - you clicked the orange "Activate" button on your dashboard of atSigns
  3. Onboarding
  4. Authenticate - subsequent authentications to your atServer using PKAM

Regarding this ticket, 1. Registration and 2. Activation has occurred, but 3. Onboarding has not yet occurred.

JeremyTubongbanua avatar Jun 29 '23 19:06 JeremyTubongbanua

I've been doing some digging, and I think the bug is coming from at_lookup. It's a big chain of different error codes, we've got

  1. "AT0015" - AtKeyNotFound thrown from at_lookup
  2. "AT0011" - InternalServerException thrown from at_lookup
  3. "AT0014" - AtClientException throw from at_client

The exceptions being thrown technically aren't incorrect? Would it be okay to leave these as is?

Anyway, I tested out my theory of it being an issue with at_lookup and got this back.

Image

Thoughts on how to proceed?

Xlin123 avatar Jul 11 '23 18:07 Xlin123

@xavierchanth@plookup:public:publickey@xavierchanth
error:AT0011-Internal server exception : Request to remote secondary @xavierchanth at null:null received error response 'AT0015-Exception: public:public:publickey@xavierchanth does not exist in keystore'
@xavierchanth@plookup:publickey@xavierchanth
data:<res>
@xavierchanth@

XavierChanth avatar Jul 11 '23 21:07 XavierChanth

When doing plookup you must not include public:

It should be plookup:publickey@alice not plookup:public:publickey@alice

gkc avatar Jul 11 '23 21:07 gkc

We really need to change the verb handlers to either be more forgiving of requests like this, or more discerning in request validation

gkc avatar Jul 11 '23 21:07 gkc

When doing plookup you must not include public:

It should be plookup:publickey@alice not plookup:public:publickey@alice

Yeah noted in my example code, we were trying to chase down Jeremy's issue and we think that it is because plookup:public:publickey@alice is getting executed...

XavierChanth avatar Jul 11 '23 21:07 XavierChanth

Oops my bad, I never realized that... but judging by jeremy's error, AtClient.get handles public keys properly (unlike how I handled them).

Regardless, the issue is really inside of at_lookup, the RemoteSecondary does handle KeyNotFoundExceptions properly but at_lookup is changing the error code to something different. (Specifically to AT0011, InternalServerException)

Xlin123 avatar Jul 11 '23 21:07 Xlin123

@murali-shris do you want me to finish this or did you want to take it over?

I haven't touched it in almost a year.

Xlin123 avatar May 13 '24 13:05 Xlin123

@murali-shris do you want me to finish this or did you want to take it over?

I haven't touched it in almost a year.

@Xlin123 I will investigate this issue in the current sprint

murali-shris avatar May 14 '24 07:05 murali-shris