microsoft / do-client

Delivery Optimization client components
MIT License
24 stars 20 forks source link

How to read ExtendedErrorCode? #193

Closed AndreRicardo-Zoetis closed 2 weeks ago

AndreRicardo-Zoetis commented 2 weeks ago

Getting "ExtendedErrorCode":"-1060110280" on deliveryoptimization-agent

Jun 14 06:05:48 vetscan deliveryoptimization-agent[484]: {"Status":"Paused","BytesTotal":"0","BytesTransferred":"0","ErrorCode":"-2133843966","ExtendedErrorCode":"-1060110280"}

I've followed the instructions here https://learn.microsoft.com/en-us/azure/iot-hub-device-update/device-update-error-codes#delivery-optimization-agent

and here on trying to decode the error code:

https://github.com/Azure/iot-hub-device-update/blob/fd69e827422f7fd8be06e04617c6cf8176bb104a/docs/how-to-troubleshoot-guide.md?plain=1#L64-L81

"ExtendedErrorCode":"-1060110280" to hex signed C0D00038

https://www.rapidtables.com/convert/number/decimal-to-hex.html?x=-1060110280

C - facility code C ?

0D - area code?

00038 in hex is 56 in decimal, not sure where to go from here.

jw-msft commented 2 weeks ago

DO content downloader calls the MAKE_ADUC_DELIVERY_OPTIMIZATION_EXTENDEDRESULTCODE macro: https://github.com/Azure/iot-hub-device-update/blob/fd69e827422f7fd8be06e04617c6cf8176bb104a/src/extensions/content_downloaders/deliveryoptimization_downloader/deliveryoptimization_content_downloader.cpp#L95

That macro is defined here: https://github.com/Azure/iot-hub-device-update/blob/fd69e827422f7fd8be06e04617c6cf8176bb104a/src/inc/aduc/result.h#L2357

ADUC_FACILITY_DELIVERY_OPTIMIZATION is defined here: https://github.com/Azure/iot-hub-device-update/blob/fd69e827422f7fd8be06e04617c6cf8176bb104a/src/inc/aduc/result.h#L102

It takes 0xD and shifts it to the left 28 (0x1c) bits, effectively appending 7 hex 0's to the end: 1101 -> 1101 0000 0000 0000 0000 0000 0000 0000 -> 0xD0 00 00 00

It masks the lower 28 bits of 0xC0D00038 (using a bitmask of 0xFFFFFFF) in this case, which chops off the 0xC Facility from DO leaving 0x00D00038, which is how this ExtendedResultsCodes should be showing up in the IotHub twin.

In this case, it seems to be errno of 56 (0x38), or EBADRQC (Invalid Request): https://github.com/torvalds/linux/blob/5be63fc19fcaa4c236b307420483578a56986a37/include/uapi/asm-generic/errno.h#L37 (It's in /usr/include/asm-generic/errno.h on my ubuntu 22.04 box)

jw-msft commented 2 weeks ago

For the Facility of 0xC, this test code seems to suggest that this is a system error (errno) code by how it bitwise-OR's in the 0xC as the highest nibble:

use of 0xC0000000: https://github.com/microsoft/do-client/blob/8362e36bb990914bb3f69a08f50f383612983002/sdk-cpp/tests/download_tests_common.cpp#L36

combined with ENOENT: https://github.com/microsoft/do-client/blob/8362e36bb990914bb3f69a08f50f383612983002/sdk-cpp/tests/download_tests_common.cpp#L164

AndreRicardo-Zoetis commented 2 weeks ago

Got it 0xD is 13 decimal for the ADUC_FACILITY_DELIVERY_OPTIMIZATION = 13.