Azure / Azure/azure-iot-hub-node

Error classes used by the SDK are not readily available

Open
#58 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3
Forks
18
PR merge metrics
No merged PRs in 30d

Description

This issue reproduces at least on the latest version of "1.16.5" available from NPM.

**Description of the problem**

The SDK has a number of error classes present in the "dist/common-core/errors.js" file but these errors are not exported by the main-level module ("iothub.js"). When the errors are not exported at the root level, a developer has to resort to code such as this:
```
import {DeviceNotFoundError} from 'azure-iothub/dist/common-core/errors';

...

try {
... some operation on the SDK ...
} catch (error) {
if (error instanceof DeviceNotFound) {
.. do something specific ..
} else {
.. do something else ..
}
}
```

In case the structure of the SDK's repository changes, or the location of "errors.js" changes across versions the code above will break.

**Proposed solution**

One way to solve the matter is to export the error classes at via the "iothub.js" file. While I am far from sure how this export is done, something like this in "iothub.js" might work:
```
module.exports = {
... other exports ...

Errors: require('./dist/common-core/errors.js')
};
```
This should result in something like this to "iothub.d.ts":
```
... other exports ...

export * from './dist/common-core/errors';
```

**Notes**

There is also an "azure-iot-common" NPM package available, which is used at least "azure-iot-sdk-node". While this library is more "client oriented" and less "hub oriented" I do see some synergy possibilities in taking a dependency to this package, and using the error classes from there instead of copy-pasting them around.

The rationale is that "azure-iot-common" exports the error classes correctly.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting the package entry point in iothub.js, the declarations in iothub.d.ts, and the existing classes in dist/common-core/errors.js. Verify how the root module currently exports SDK symbols and determine whether the error classes should be exposed directly or under Errors. Done means consumers can import the error classes from the package root without relying on the internal dist path.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.