pax_global_header00006660000000000000000000000064144634305040014515gustar00rootroot0000000000000052 comment=9d9003f5db6c22fbc0fb66450cf5e4675fcb7be8 ruby-google-cloud-errors-1.3.1/000077500000000000000000000000001446343050400163705ustar00rootroot00000000000000ruby-google-cloud-errors-1.3.1/.yardopts000066400000000000000000000002521446343050400202350ustar00rootroot00000000000000--no-private --title=Google Cloud Errors --markup markdown --markup-provider redcarpet ./lib/**/*.rb - README.md CONTRIBUTING.md CHANGELOG.md CODE_OF_CONDUCT.md LICENSE ruby-google-cloud-errors-1.3.1/CODE_OF_CONDUCT.md000066400000000000000000000036771446343050400212040ustar00rootroot00000000000000# Contributor Code of Conduct As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery * Personal attacks * Trolling or insulting/derogatory comments * Public or private harassment * Publishing other's private information, such as physical or electronic addresses, without explicit permission * Other unethical or unprofessional conduct. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) ruby-google-cloud-errors-1.3.1/CONTRIBUTING.md000066400000000000000000000076541446343050400206350ustar00rootroot00000000000000# Contributing to Google Cloud 1. **Sign one of the contributor license agreements below.** 2. Fork the repo, develop and test your code changes. 3. Send a pull request. ## Contributor License Agreements Before we can accept your pull requests you'll need to sign a Contributor License Agreement (CLA): - **If you are an individual writing original source code** and **you own the intellectual property**, then you'll need to sign an [individual CLA](https://developers.google.com/open-source/cla/individual). - **If you work for a company that wants to allow you to contribute your work**, then you'll need to sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). You can sign these electronically (just scroll to the bottom). After that, we'll be able to accept your pull requests. ## Setup In order to use the google-cloud console and run the project's tests, there is a small amount of setup: 1. Install Ruby. google-cloud requires Ruby 2.5+. You may choose to manage your Ruby and gem installations with [RVM](https://rvm.io/), [rbenv](https://github.com/rbenv/rbenv), or [chruby](https://github.com/postmodern/chruby). 2. Install [Bundler](http://bundler.io/). ```sh $ gem install bundler ``` 3. Install the top-level project dependencies. ```sh $ bundle install ``` 4. Install the Google Cloud dependencies. ```sh $ cd google-cloud-errors/ $ bundle install ``` ## Google Cloud Tests Tests are very important part of google-cloud. All contributions should include tests that ensure the contributed code behaves as expected. To run the unit tests, documentation tests, and code style checks together for a package: ``` sh $ cd google-cloud-errors/ $ bundle exec rake ci ``` To run the command above, plus all acceptance tests, use `rake ci:acceptance` or its handy alias, `rake ci:a`. ### Google Cloud Unit Tests The project uses the [minitest](https://github.com/seattlerb/minitest) library, including [specs](https://github.com/seattlerb/minitest#specs), [mocks](https://github.com/seattlerb/minitest#mocks) and [minitest-autotest](https://github.com/seattlerb/minitest-autotest). To run the Google Cloud unit tests: ``` sh $ cd google-cloud-errors/ $ bundle exec rake test ``` ### Google Cloud Documentation Tests The project tests the code examples in the gem's [YARD](https://github.com/lsegal/yard)-based documentation. The example testing functions in a way that is very similar to unit testing, and in fact the library providing it, [yard-doctest](https://github.com/p0deje/yard-doctest), is based on the project's unit test library, [minitest](https://github.com/seattlerb/minitest). To run the Google Cloud documentation tests: ``` sh $ cd google-cloud-errors/ $ bundle exec rake doctest ``` If you add, remove or modify documentation examples when working on a pull request, you may need to update the setup for the tests. The stubs and mocks required to run the tests are located in `support/doctest_helper.rb`. Please note that much of the setup is matched by the title of the [`@example`](http://www.rubydoc.info/gems/yard/file/docs/Tags.md#example) tag. If you alter an example's title, you may encounter breaking tests. ## Coding Style Please follow the established coding style in the library. The style is is largely based on [The Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) with a few exceptions based on seattle-style: * Avoid parenthesis when possible, including in method definitions. * Always use double quotes strings. ([Option B](https://github.com/bbatsov/ruby-style-guide#strings)) You can check your code against these rules by running Rubocop like so: ```sh $ cd google-cloud-errors/ $ bundle exec rake rubocop ``` ## Code of Conduct Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See {file:CODE_OF_CONDUCT.md Code of Conduct} for more information. ruby-google-cloud-errors-1.3.1/LICENSE000066400000000000000000000261371446343050400174060ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 https://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ruby-google-cloud-errors-1.3.1/README.md000066400000000000000000000037361446343050400176600ustar00rootroot00000000000000# google-cloud-errors This library contains error classes raised by Google Cloud API clients. Please see the [GitHub repository](https://github.com/googleapis/google-cloud-ruby) for more information about Google Cloud gems. - [google-cloud-errors API documentation](https://googleapis.dev/ruby/google-cloud-errors/latest) ## Supported Ruby Versions This library is supported on Ruby 2.5+. Google provides official support for Ruby versions that are actively supported by Ruby Core—that is, Ruby versions that are either in normal maintenance or in security maintenance, and not end of life. Currently, this means Ruby 2.5 and later. Older versions of Ruby _may_ still work, but are unsupported and not recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details about the Ruby support schedule. ## Versioning This library follows [Semantic Versioning](http://semver.org/). It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable. ## Contributing Contributions to this library are always welcome and highly encouraged. See the [Contributing Guide](https://googleapis.dev/ruby/google-cloud-errors/latest/file.CONTRIBUTING.html) for more information on how to get started. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct](https://googleapis.dev/ruby/google-cloud-errors/latest/file.CODE_OF_CONDUCT.html) for more information. ## License This library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://googleapis.dev/ruby/google-cloud-errors/latest/file.LICENSE.html). ## Support Please report bugs [on Github](https://github.com/googleapis/google-cloud-ruby/issues). Don't hesitate to [ask questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby) about the client or APIs on [StackOverflow](http://stackoverflow.com). ruby-google-cloud-errors-1.3.1/google-cloud-errors.gemspec000066400000000000000000000052221446343050400236300ustar00rootroot00000000000000######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: google-cloud-errors 1.3.1 ruby lib Gem::Specification.new do |s| s.name = "google-cloud-errors".freeze s.version = "1.3.1" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Mike Moore".freeze, "Chris Smith".freeze] s.date = "2023-02-28" s.description = "google-cloud-errors defines error classes for google-cloud-ruby.".freeze s.email = ["mike@blowmage.com".freeze, "quartzmo@gmail.com".freeze] s.files = [".yardopts".freeze, "CODE_OF_CONDUCT.md".freeze, "CONTRIBUTING.md".freeze, "LICENSE".freeze, "README.md".freeze, "lib/google-cloud-errors.rb".freeze, "lib/google/cloud/errors.rb".freeze, "lib/google/cloud/errors/version.rb".freeze] s.homepage = "https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-errors".freeze s.licenses = ["Apache-2.0".freeze] s.required_ruby_version = Gem::Requirement.new(">= 2.5".freeze) s.rubygems_version = "3.2.5".freeze s.summary = "Error classes for google-cloud-ruby".freeze if s.respond_to? :specification_version then s.specification_version = 4 end if s.respond_to? :add_runtime_dependency then s.add_development_dependency(%q.freeze, ["~> 1.1"]) s.add_development_dependency(%q.freeze, ["~> 1.25.1"]) s.add_development_dependency(%q.freeze, ["~> 5.14"]) s.add_development_dependency(%q.freeze, ["~> 1.0"]) s.add_development_dependency(%q.freeze, ["~> 1.1"]) s.add_development_dependency(%q.freeze, ["~> 5.2"]) s.add_development_dependency(%q.freeze, ["~> 3.0"]) s.add_development_dependency(%q.freeze, ["~> 0.9"]) s.add_development_dependency(%q.freeze, ["~> 0.9"]) s.add_development_dependency(%q.freeze, ["~> 0.1.13"]) else s.add_dependency(%q.freeze, ["~> 1.1"]) s.add_dependency(%q.freeze, ["~> 1.25.1"]) s.add_dependency(%q.freeze, ["~> 5.14"]) s.add_dependency(%q.freeze, ["~> 1.0"]) s.add_dependency(%q.freeze, ["~> 1.1"]) s.add_dependency(%q.freeze, ["~> 5.2"]) s.add_dependency(%q.freeze, ["~> 3.0"]) s.add_dependency(%q.freeze, ["~> 0.9"]) s.add_dependency(%q.freeze, ["~> 0.9"]) s.add_dependency(%q.freeze, ["~> 0.1.13"]) end end ruby-google-cloud-errors-1.3.1/lib/000077500000000000000000000000001446343050400171365ustar00rootroot00000000000000ruby-google-cloud-errors-1.3.1/lib/google-cloud-errors.rb000066400000000000000000000012051446343050400233530ustar00rootroot00000000000000# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require "google/cloud/errors" require "google/cloud/errors/version" ruby-google-cloud-errors-1.3.1/lib/google/000077500000000000000000000000001446343050400204125ustar00rootroot00000000000000ruby-google-cloud-errors-1.3.1/lib/google/cloud/000077500000000000000000000000001446343050400215205ustar00rootroot00000000000000ruby-google-cloud-errors-1.3.1/lib/google/cloud/errors.rb000066400000000000000000000353131446343050400233660ustar00rootroot00000000000000# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require "English" module Google module Cloud ## # Base google-cloud exception class. class Error < StandardError ## # Construct a new Google::Cloud::Error object, optionally passing in a # message. # # @param msg [String, nil] an error message def initialize msg = nil super end ## # Returns the value of `status_code` from the underlying cause error # object, if both are present. Otherwise returns `nil`. # # This is typically present on errors originating from calls to an API # over HTTP/REST. # # @return [Object, nil] def status_code return nil unless cause.respond_to? :status_code cause.status_code end ## # Returns the value of `body` from the underlying cause error # object, if both are present. Otherwise returns `nil`. # # This is typically present on errors originating from calls to an API # over HTTP/REST. # # @return [Object, nil] def body return nil unless cause.respond_to? :body cause.body end ## # Returns the value of `header` from the underlying cause error # object, if both are present. Otherwise returns `nil`. # # This is typically present on errors originating from calls to an API # over HTTP/REST. # # @return [Object, nil] def header return nil unless cause.respond_to? :header cause.header end ## # Returns the value of `code` from the underlying cause error # object, if both are present. Otherwise returns `nil`. # # This is typically present on errors originating from calls to an API # over gRPC. # # @return [Object, nil] def code return nil unless cause.respond_to? :code cause.code end ## # Returns the value of `details` from the underlying cause error # object, if both are present. Otherwise returns `nil`. # # This is typically present on errors originating from calls to an API # over gRPC. # # @return [Object, nil] def details return nil unless cause.respond_to? :details cause.details end ## # Returns the value of `metadata` from the underlying cause error # object, if both are present. Otherwise returns `nil`. # # This is typically present on errors originating from calls to an API # over gRPC. # # @return [Object, nil] def metadata return nil unless cause.respond_to? :metadata cause.metadata end ## # Returns the value of `status_details` from the underlying cause error # object, if both are present. Otherwise returns `nil`. # # This is typically present on errors originating from calls to an API # over gRPC. # # @return [Object, nil] def status_details return nil unless cause.respond_to? :status_details cause.status_details end ## # Returns the `::Google::Rpc::ErrorInfo` object present in the `status_details` # or `details` array, given that the following is true: # * either `status_details` or `details` exists and is an array # * there is exactly one `::Google::Rpc::ErrorInfo` object in that array. # Looks in `status_details` first, then in `details`. # # @return [::Google::Rpc::ErrorInfo, nil] def error_info @error_info ||= begin check_property = lambda do |prop| if prop.is_a? Array error_infos = prop.find_all { |status| status.is_a?(::Google::Rpc::ErrorInfo) } if error_infos.length == 1 error_infos[0] end end end check_property.call(status_details) || check_property.call(details) end end ## # Returns the value of `domain` from the `::Google::Rpc::ErrorInfo` # object, if it exists in the `status_details` array. # # This is typically present on errors originating from calls to an API # over gRPC. # # @return [Object, nil] def domain return nil unless error_info.respond_to? :domain error_info.domain end ## # Returns the value of `reason` from the `::Google::Rpc::ErrorInfo` # object, if it exists in the `status_details` array. # # This is typically present on errors originating from calls to an API # over gRPC. # # @return [Object, nil] def reason return nil unless error_info.respond_to? :reason error_info.reason end ## # Returns the value of `metadata` from the `::Google::Rpc::ErrorInfo` # object, if it exists in the `status_details` array. # # This is typically present on errors originating from calls to an API # over gRPC. # # @return [Hash, nil] def error_metadata return nil unless error_info.respond_to? :metadata error_info.metadata.to_h end # @private Create a new error object from a client error def self.from_error error klass = if error.respond_to? :code grpc_error_class_for error.code elsif error.respond_to? :status_code gapi_error_class_for error.status_code else self end klass.new error.message end # @private Identify the subclass for a gRPC error def self.grpc_error_class_for grpc_error_code # The gRPC status code 0 is for a successful response. # So there is no error subclass for a 0 status code, use current class. [ self, CanceledError, UnknownError, InvalidArgumentError, DeadlineExceededError, NotFoundError, AlreadyExistsError, PermissionDeniedError, ResourceExhaustedError, FailedPreconditionError, AbortedError, OutOfRangeError, UnimplementedError, InternalError, UnavailableError, DataLossError, UnauthenticatedError ][grpc_error_code] || self end # @private Identify the subclass for a Google API Client error def self.gapi_error_class_for http_status_code # The http status codes mapped to their error classes. { 400 => InvalidArgumentError, # FailedPreconditionError/OutOfRangeError 401 => UnauthenticatedError, 403 => PermissionDeniedError, 404 => NotFoundError, 409 => AlreadyExistsError, # AbortedError 412 => FailedPreconditionError, 429 => ResourceExhaustedError, 499 => CanceledError, 500 => InternalError, # UnknownError/DataLossError 501 => UnimplementedError, 503 => UnavailableError, 504 => DeadlineExceededError }[http_status_code] || self end end ## # Canceled indicates the operation was cancelled (typically by the caller). class CanceledError < Error ## # gRPC error code for CANCELLED # # @return [Integer] def code 1 end end ## # Unknown error. An example of where this error may be returned is # if a Status value received from another address space belongs to # an error-space that is not known in this address space. Also # errors raised by APIs that do not return enough error information # may be converted to this error. class UnknownError < Error ## # gRPC error code for UNKNOWN # # @return [Integer] def code 2 end end ## # InvalidArgument indicates client specified an invalid argument. # Note that this differs from FailedPrecondition. It indicates arguments # that are problematic regardless of the state of the system # (e.g., a malformed file name). class InvalidArgumentError < Error ## # gRPC error code for INVALID_ARGUMENT # # @return [Integer] def code 3 end end ## # DeadlineExceeded means operation expired before completion. # For operations that change the state of the system, this error may be # returned even if the operation has completed successfully. For # example, a successful response from a server could have been delayed # long enough for the deadline to expire. class DeadlineExceededError < Error ## # gRPC error code for DEADLINE_EXCEEDED # # @return [Integer] def code 4 end end ## # NotFound means some requested entity (e.g., file or directory) was # not found. class NotFoundError < Error ## # gRPC error code for NOT_FOUND # # @return [Integer] def code 5 end end ## # AlreadyExists means an attempt to create an entity failed because one # already exists. class AlreadyExistsError < Error ## # gRPC error code for ALREADY_EXISTS # # @return [Integer] def code 6 end end ## # PermissionDenied indicates the caller does not have permission to # execute the specified operation. It must not be used for rejections # caused by exhausting some resource (use ResourceExhausted # instead for those errors). It must not be # used if the caller cannot be identified (use Unauthenticated # instead for those errors). class PermissionDeniedError < Error ## # gRPC error code for PERMISSION_DENIED # # @return [Integer] def code 7 end end ## # ResourceExhausted indicates some resource has been exhausted, perhaps # a per-user quota, or perhaps the entire file system is out of space. class ResourceExhaustedError < Error ## # gRPC error code for RESOURCE_EXHAUSTED # # @return [Integer] def code 8 end end ## # FailedPrecondition indicates operation was rejected because the # system is not in a state required for the operation's execution. # For example, directory to be deleted may be non-empty, an rmdir # operation is applied to a non-directory, etc. # # A litmus test that may help a service implementor in deciding # between FailedPrecondition, Aborted, and Unavailable: # (a) Use Unavailable if the client can retry just the failing call. # (b) Use Aborted if the client should retry at a higher-level # (e.g., restarting a read-modify-write sequence). # (c) Use FailedPrecondition if the client should not retry until # the system state has been explicitly fixed. E.g., if an "rmdir" # fails because the directory is non-empty, FailedPrecondition # should be returned since the client should not retry unless # they have first fixed up the directory by deleting files from it. # (d) Use FailedPrecondition if the client performs conditional # REST Get/Update/Delete on a resource and the resource on the # server does not match the condition. E.g., conflicting # read-modify-write on the same resource. class FailedPreconditionError < Error ## # gRPC error code for FAILED_PRECONDITION # # @return [Integer] def code 9 end end ## # Aborted indicates the operation was aborted, typically due to a # concurrency issue like sequencer check failures, transaction aborts, # etc. # # See litmus test above for deciding between FailedPrecondition, # Aborted, and Unavailable. class AbortedError < Error ## # gRPC error code for ABORTED # # @return [Integer] def code 10 end end ## # OutOfRange means operation was attempted past the valid range. # E.g., seeking or reading past end of file. # # Unlike InvalidArgument, this error indicates a problem that may # be fixed if the system state changes. For example, a 32-bit file # system will generate InvalidArgument if asked to read at an # offset that is not in the range [0,2^32-1], but it will generate # OutOfRange if asked to read from an offset past the current # file size. # # There is a fair bit of overlap between FailedPrecondition and # OutOfRange. We recommend using OutOfRange (the more specific # error) when it applies so that callers who are iterating through # a space can easily look for an OutOfRange error to detect when # they are done. class OutOfRangeError < Error ## # gRPC error code for OUT_OF_RANGE # # @return [Integer] def code 11 end end ## # Unimplemented indicates operation is not implemented or not # supported/enabled in this service. class UnimplementedError < Error ## # gRPC error code for UNIMPLEMENTED # # @return [Integer] def code 12 end end ## # Internal errors. Means some invariants expected by underlying # system has been broken. If you see one of these errors, # something is very broken. class InternalError < Error ## # gRPC error code for INTERNAL # # @return [Integer] def code 13 end end ## # Unavailable indicates the service is currently unavailable. # This is a most likely a transient condition and may be corrected # by retrying with a backoff. # # See litmus test above for deciding between FailedPrecondition, # Aborted, and Unavailable. class UnavailableError < Error ## # gRPC error code for UNAVAILABLE # # @return [Integer] def code 14 end end ## # DataLoss indicates unrecoverable data loss or corruption. class DataLossError < Error ## # gRPC error code for DATA_LOSS # # @return [Integer] def code 15 end end ## # Unauthenticated indicates the request does not have valid # authentication credentials for the operation. class UnauthenticatedError < Error ## # gRPC error code for UNAUTHENTICATED # # @return [Integer] def code 16 end end end end ruby-google-cloud-errors-1.3.1/lib/google/cloud/errors/000077500000000000000000000000001446343050400230345ustar00rootroot00000000000000ruby-google-cloud-errors-1.3.1/lib/google/cloud/errors/version.rb000066400000000000000000000012411446343050400250440ustar00rootroot00000000000000# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. module Google module Cloud module Errors VERSION = "1.3.1".freeze end end end