Skip to content

Problems with invalid pair parameters #131

@rube200

Description

@rube200

Describe the bug

When i try to pair to a device with valid paramters (ip, port and code) everything works fine.
The problem is when i use a wrong port/code to pair the device, currently the app crashes because it fails to read the msg return by adb.

Log:

An unhandled exception has occurred while executing the request.
    System.FormatException: The input string 'FAIL' was not in a correct format.
    at System.Number.ThrowFormatException[TChar](ReadOnlySpan`1 value)
    at System.Int32.Parse(String s, NumberStyles style)
    at AdvancedSharpAdbClient.AdbSocket.ReadStringAsync(CancellationToken cancellationToken)
    at AdvancedSharpAdbClient.AdbClient.PairAsync(String host, Int32 port, String code, CancellationToken cancellationToken)

After some digging i found the problem could be the adb tools itself, this is example of error when doing it directly in terminal with wrong port/code:

>adb pair 192.168.2.100:123123 123123
error: protocol fault (couldn't read status message): No error

Steps to reproduce the bug

Just call

await new AdbClient().PairAsync("some ip", 123, "some wrong code", CancellationToken.None);

The app will crash throwing System.FormatException

Expected behavior

Expected to return an error in message instead of crashing.

NuGet package version

3.5.15

.NET Platform

.NET 10

Platform type

Windows

System version

>adb version
Android Debug Bridge version 1.0.41
Version 36.0.0-13206524
Installed as D:\Android\Android_Sdk\platform-tools\adb.exe
Running on Windows 10.0.26100

IDE

Rider 2025

Additional context

After some debugging i found this are the messages return by adb socket:

"FAIL0027Failed: Unable to start pairing client." //When ip/port is wrong
"FAIL0031Failed: Wrong password or connection was dropped." //When pair code is wrong
"0045Successfully paired to 192.168.2.100:40613 [guid=REDACTED]" //On Success

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions