Azure / Azure/azure-iot-sdk-csharp

[Bug Report]RegistryManager.GetDeviceAsync() returns null

Open
#3,473 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
477
Forks
492
Avg merge
9h 55m
Merged PRs (30d)
2

Description

# Context

- **OS, version, SKU and CPU architecture used:** Azure Function Dotnet isolated Windows
- **Application's .NET Target Framework :** net8.0
- **Device:** N/A
- **SDK version used:**

## Description of the issue
RegistryManager.GetDeviceAsync (string deviceId) returns a null if device is not found.
Per Code Expected DeviceNotFoundException

``` public virtual Task GetDeviceAsync(string deviceId, CancellationToken cancellationToken)
{
if (Logging.IsEnabled)
Logging.Enter(this, $"Getting device: {deviceId}", nameof(GetDeviceAsync));
try
{
if (string.IsNullOrWhiteSpace(deviceId))
{
throw new ArgumentException(IotHubApiResources.GetString(ApiResources.ParameterCannotBeNullOrWhitespace, "deviceId"));
}

EnsureInstanceNotClosed();
var errorMappingOverrides = new Dictionary>>()
{
{ HttpStatusCode.NotFound, async responseMessage => new DeviceNotFoundException(await ExceptionHandlingHelper.GetExceptionMessageAsync(responseMessage).ConfigureAwait(false)) }
};

return _httpClientHelper.GetAsync(GetRequestUri(deviceId), errorMappingOverrides, null, false, cancellationToken);
```
## Code sample exhibiting the issue
[Fact]
public async Task TestRegistryManager()
{
var registry = RegistryManager.CreateFromConnectionString(connectionString);

await Assert.ThrowsAsync(async () => await registry.GetDeviceAsync("IDoNoTExist") );
}

## Console log of the issue
Follow the instructions [here](https://github.com/Azure/azure-iot-sdk-csharp/tree/main/tools/CaptureLogs) to capture SDK logs.
Don't forget to remove any connection string information!

Contributor guide

Open the contributing guide

Research direction

Start at RegistryManager.GetDeviceAsync(string deviceId) and compare its not-found handling with the behavior shown in TestRegistryManager. Reproduce the call with the non-existent device ID "IDoNoTExist" and verify whether the result is null or a DeviceNotFoundException. Done means the behavior matches the documented exception expectation and the test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.