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

fix(property-provider): manually adjust the prototype of *ProviderError #3445

Merged
merged 1 commit into from
Mar 21, 2022

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Mar 18, 2022

Issue

Fixes: #3444

Description

Manually adjust the prototype of *ProviderError

Testing

Verified that instanceof checks succeed for ES5 versions of *ProviderError

const { __extends } = require("tslib");

var ProviderError = (function (_super) {
  __extends(ProviderError, _super);
  function ProviderError(message, tryNextLink) {
    if (tryNextLink === void 0) {
      tryNextLink = true;
    }
    var _this = _super.call(this, message) || this;
    _this.tryNextLink = tryNextLink;
    _this.name = "ProviderError";
    Object.setPrototypeOf(_this, ProviderError.prototype);
    return _this;
  }
  ProviderError.from = function (error, tryNextLink) {
    if (tryNextLink === void 0) {
      tryNextLink = true;
    }
    return Object.assign(new this(error.message, tryNextLink), error);
  };
  return ProviderError;
})(Error);

var CredentialsProviderError = (function (_super) {
  __extends(CredentialsProviderError, _super);
  function CredentialsProviderError(message, tryNextLink) {
    if (tryNextLink === void 0) {
      tryNextLink = true;
    }
    var _this = _super.call(this, message, tryNextLink) || this;
    _this.tryNextLink = tryNextLink;
    _this.name = "CredentialsProviderError";
    Object.setPrototypeOf(_this, CredentialsProviderError.prototype);
    return _this;
  }
  return CredentialsProviderError;
})(ProviderError);

[Error, ProviderError].forEach((ErrorFn) => {
  console.log(new ProviderError("PANIC") instanceof ErrorFn);
  console.log(ProviderError.from(new Error("PANIC")) instanceof ErrorFn);
});

[Error, ProviderError, CredentialsProviderError].forEach((ErrorFn) => {
  console.log(new CredentialsProviderError("PANIC") instanceof ErrorFn);
  console.log(
    CredentialsProviderError.from(new Error("PANIC")) instanceof ErrorFn
  );
});

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr requested a review from a team as a code owner March 18, 2022 15:41
@trivikr trivikr merged commit 134f769 into aws:main Mar 21, 2022
@trivikr trivikr deleted the provider-error-set-prototype-of branch March 21, 2022 17:25
@github-actions
Copy link

github-actions bot commented Apr 5, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The instanceof check fails on ProviderError, and CredentialsProviderError in ES5
2 participants