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

[Bug Report]RegistryManager.GetDeviceAsync() returns null #3473

Open
Gamecock opened this issue Oct 11, 2024 · 1 comment
Open

[Bug Report]RegistryManager.GetDeviceAsync() returns null #3473

Gamecock opened this issue Oct 11, 2024 · 1 comment
Labels
bug Something isn't working.

Comments

@Gamecock
Copy link

Gamecock commented Oct 11, 2024

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

        {
            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, Func<HttpResponseMessage, Task<Exception>>>()
                {
                    { HttpStatusCode.NotFound, async responseMessage => new DeviceNotFoundException(await ExceptionHandlingHelper.GetExceptionMessageAsync(responseMessage).ConfigureAwait(false)) }
                };

                return _httpClientHelper.GetAsync<Device>(GetRequestUri(deviceId), errorMappingOverrides, null, false, cancellationToken);

Code sample exhibiting the issue

[Fact]
public async Task TestRegistryManager()
{
    var registry = RegistryManager.CreateFromConnectionString(connectionString);

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

Console log of the issue

Follow the instructions here to capture SDK logs.
Don't forget to remove any connection string information!

@Gamecock Gamecock added the bug Something isn't working. label Oct 11, 2024
@Gamecock
Copy link
Author

Documentation update to be clear non this behavior might be sufficient, but the DFE matches what is received from rest of SDK.

@Gamecock Gamecock changed the title [Bug Report] [Bug Report]RegistryManager.GetDeviceAsync() returns null Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

1 participant