RestError prototype mismatches class name instead is Error
See original GitHub issue- Package Name: @azure/storage-blob
- Package Version: 12.11
- nodejs
- version: v16.15.0
- typescript
- version: v4.8.2
Describe the bug Facing issue with RestError imported from @azure/storage-blob.https://github.dev/Azure/azure-sdk-for-js/blob/80949a8a07f168c1e45188f52d9ddf09fffa8edc/sdk/core/core-http/src/restError.ts#L1
To Reproduce
console.error("Value of `e.name`", e.name);
console.error("Value of `e.__proto__`", e.__proto__);
console.error(
"Value of `e instanceof RestError`",
e instanceof RestError
);
console.error(
"Value of `Object.getPrototypeOf(e)`",
Object.getPrototypeOf(e)
);
[2022-08-26T06:16:53.310Z] Value of `e.name`: RestError
[2022-08-26T06:16:53.310Z] Value of `e.__proto__`: [Error]
[2022-08-26T06:16:53.311Z] Value of `e instanceof RestError`: false
[2022-08-26T06:16:53.311Z] Value of `Object.getPrototypeOf(e)`: [Error]
Expected behavior RestError event name to match its prototype.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Example usage for org.springframework.util MultiValueMap size
In this page you can find the example usage for org.springframework.util MultiValueMap size. Prototype. int size();. Source Link. Document. Returns the number ...
Read more >CHANGELOG.md - cosmos/cosmos-sdk - Sourcegraph
(x/auth)#13780 Querying with id (type of int64) in AccountAddressByID grpc query now throws error, use account-id(type of uint64) instead. (snapshots) 14048 ...
Read more >SWI-Prolog 3.2
This manual does not describe the full syntax and semantics of Prolog, ... This includes 'Do What I Mean', automatic completion of atom...
Read more >Supplemental Document: BIG-IP 15.0.0 Fixes and Known Issues
744685, 2-Critical, BIG-IP does not throw error when intermediate CA ... show ltm virtual <vs-name> policies does not display policy-stats.
Read more >AD-A278, 165 i. - DTIC
The use of registered names, trademarks etc. in this publication does not ... responsibility or liability for any errors or omissions that may...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Going to close this for now as I don’t think there’s specific work we intend to do in core for this, but please re-open if I’m missing something!
Ah yes, this is one of the issues that can arise. The other problem with
instanceof
is if you end up in a situation where you depend on different versions of the package that provides the error. We have a guideline related to this: https://azure.github.io/azure-sdk/typescript_implementation.html#ts-error-use-nameBecause we are not totally heartless, we now provide a type guard you can use to avoid having to hand-roll your own detection logic: https://github.com/Azure/azure-sdk-for-js/blob/c4eeff48104c47035bc99d4fc4c118fd06b1d9e8/sdk/core/core-rest-pipeline/src/restError.ts#L93
In general, we plan to provide type guards for all custom errors to make life easier for consumers. Please let us know if you find some are missing.
Yes, please file an issue for this. I feel like the handling can be improved here. /cc @vicancy