Skip to content

Errors from GetMe are silently swallowed in AuthorizationStateReadyGetMe #248

@neverwhatlose

Description

@neverwhatlose

The method in question is AuthorizationStateReadyGetMe#onUpdate(UpdateAuthorizationState update)

public void onUpdate(UpdateAuthorizationState update) {

The issue is at this line

Description:

I think there's a potential issue.

client.send(new GetMe(), me -> {  
    try {  
       if (me.getConstructor() == Error.CONSTRUCTOR) {  
          throw new TelegramError((Error) me);  
       }  
       this.me.set((User) me);  
    } finally {  
       this.meReceived.complete(null);  
    }

When me.getConstructor() returns Error, TelegramError is thrown. But despite the failure, the code still completes the CompletableFuture successfully: this.meReceived.complete(null);

This seems inconsistent because the caller may receive a stale or incorrect value of me. The error is currently only visible through logger.warn("Failed to execute TdApi.GetMe()") in the logs, which is not sufficient because callers cannot programmatically detect the failure.

Instead, the logic could be split into success and failure paths using completeExceptionally():

try {
    if (me.getConstructor() == Error.CONSTRUCTOR) {
        throw new TelegramError((Error) me);
    }
    this.me.set((User) me);
-} finally {
    this.meReceived.complete(null);
+} catch (Throwable t) {
+    this.meReceived.completeExceptionally(t);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions