github.com/pulumi/pulumi/sdk/v3@v3.108.1/nodejs/errors.ts (about)

     1  // Copyright 2016-2018, Pulumi Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  import * as grpc from "@grpc/grpc-js";
    16  
    17  import { Resource } from "./resource";
    18  import * as utils from "./utils";
    19  
    20  /**
    21   * RunError can be used for terminating a program abruptly, but resulting in a clean exit rather
    22   * than the usual verbose unhandled error logic which emits the source program text and complete
    23   * stack trace.  This type should be rarely used.  Ideally ResourceError should always be used so
    24   * that as many errors as possible can be associated with a Resource.
    25   */
    26  export class RunError extends Error {
    27      /**
    28       * A private field to help with RTTI that works in SxS scenarios.
    29       * @internal
    30       */
    31      // eslint-disable-next-line @typescript-eslint/naming-convention,no-underscore-dangle,id-blacklist,id-match
    32      public readonly __pulumiRunError: boolean = true;
    33  
    34      /**
    35       * Returns true if the given object is an instance of a RunError.  This is designed to work even when
    36       * multiple copies of the Pulumi SDK have been loaded into the same process.
    37       */
    38      public static isInstance(obj: any): obj is RunError {
    39          return utils.isInstance<RunError>(obj, "__pulumiRunError");
    40      }
    41  }
    42  
    43  /**
    44   * ResourceError can be used for terminating a program abruptly, specifically associating the
    45   * problem with a Resource.  Depending on the nature of the problem, clients can choose whether or
    46   * not a call stack should be returned as well.  This should be very rare, and would only indicate
    47   * no usefulness of presenting that stack to the user.
    48   */
    49  export class ResourceError extends Error {
    50      /**
    51       * A private field to help with RTTI that works in SxS scenarios.
    52       * @internal
    53       */
    54      // eslint-disable-next-line @typescript-eslint/naming-convention, no-underscore-dangle, id-blacklist, id-match
    55      public readonly __pulumResourceError: boolean = true;
    56  
    57      /**
    58       * Returns true if the given object is an instance of a ResourceError.  This is designed to work even when
    59       * multiple copies of the Pulumi SDK have been loaded into the same process.
    60       */
    61      public static isInstance(obj: any): obj is ResourceError {
    62          return utils.isInstance<ResourceError>(obj, "__pulumResourceError");
    63      }
    64  
    65      constructor(message: string, public resource: Resource | undefined, public hideStack?: boolean) {
    66          super(message);
    67      }
    68  }
    69  
    70  export function isGrpcError(err: Error): boolean {
    71      const code = (<any>err).code;
    72      return code === grpc.status.UNAVAILABLE || code === grpc.status.CANCELLED;
    73  }