question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
xirzeccommented, Aug 29, 2022

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!

0reactions
xirzeccommented, Aug 29, 2022

Turns out that WebPubSub uses the RestError from @azure/core-rest-pipeline. That is why the instanceof in our runtime is returning false, they are not the same RestError.

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-name

Because 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.

Also, the fact that messages are coming through as empty strings should probably be fixed or investigated. Do let me know if you want me to open a separate issue for that: https://github.com/Azure/azure-sdk-for-js/blame/480e82cd0f9a8c40cd4ce66df978962661014c19/sdk/web-pubsub/web-pubsub/src/hubClient.ts#L513

Yes, please file an issue for this. I feel like the handling can be improved here. /cc @vicancy

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found