google-cloud-errors 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c454f54bb24cc8e46dd5b0953ea1d00ba3782ded1ad763443eefc9b82cd29c8a
4
+ data.tar.gz: 3d16c10fc121886aa68f4aaca2dad4242b0349c526eacc57773dd271543f1073
5
+ SHA512:
6
+ metadata.gz: c0400faa491e0e3679eced016f634c29e3264181b1f04b15b71e7f98f088f3bf922a4a6c8000a5a5c2ceb058a3c5a9dda4d44c2ba84c9d629930f8ad12ee9d77
7
+ data.tar.gz: 7be40dae2d36036d2eac8e68b827fdfcdab903972b2127e04b53254ffc25554f625d492a4a1b992bded9d8032d3819396a4ee065e53cec1cc1c1bafd18cb243c
data/.yardopts ADDED
@@ -0,0 +1,12 @@
1
+ --no-private
2
+ --title=Google Cloud Errors
3
+ --markup markdown
4
+ --markup-provider redcarpet
5
+
6
+ ./lib/**/*.rb
7
+ -
8
+ README.md
9
+ CONTRIBUTING.md
10
+ CHANGELOG.md
11
+ CODE_OF_CONDUCT.md
12
+ LICENSE
@@ -0,0 +1,40 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct.
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or reject
24
+ comments, commits, code, wiki edits, issues, and other contributions that are
25
+ not aligned to this Code of Conduct. By adopting this Code of Conduct, project
26
+ maintainers commit themselves to fairly and consistently applying these
27
+ principles to every aspect of managing this project. Project maintainers who do
28
+ not follow or enforce the Code of Conduct may be permanently removed from the
29
+ project team.
30
+
31
+ This code of conduct applies both within project spaces and in public spaces
32
+ when an individual is representing the project or its community.
33
+
34
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
35
+ reported by opening an issue or contacting one or more of the project
36
+ maintainers.
37
+
38
+ This Code of Conduct is adapted from the [Contributor
39
+ Covenant](http://contributor-covenant.org), version 1.2.0, available at
40
+ [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,141 @@
1
+ # Contributing to Google Cloud
2
+
3
+ 1. **Sign one of the contributor license agreements below.**
4
+ 2. Fork the repo, develop and test your code changes.
5
+ 3. Send a pull request.
6
+
7
+ ## Contributor License Agreements
8
+
9
+ Before we can accept your pull requests you'll need to sign a Contributor
10
+ License Agreement (CLA):
11
+
12
+ - **If you are an individual writing original source code** and **you own the
13
+ intellectual property**, then you'll need to sign an [individual
14
+ CLA](https://developers.google.com/open-source/cla/individual).
15
+ - **If you work for a company that wants to allow you to contribute your work**,
16
+ then you'll need to sign a [corporate
17
+ CLA](https://developers.google.com/open-source/cla/corporate).
18
+
19
+ You can sign these electronically (just scroll to the bottom). After that, we'll
20
+ be able to accept your pull requests.
21
+
22
+ ## Setup
23
+
24
+ In order to use the google-cloud console and run the project's tests,
25
+ there is a small amount of setup:
26
+
27
+ 1. Install Ruby. google-cloud requires Ruby 2.4+. You may choose to
28
+ manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
+ [rbenv](https://github.com/rbenv/rbenv), or
30
+ [chruby](https://github.com/postmodern/chruby).
31
+
32
+ 2. Install [Bundler](http://bundler.io/).
33
+
34
+ ```sh
35
+ $ gem install bundler
36
+ ```
37
+
38
+ 3. Install the top-level project dependencies.
39
+
40
+ ```sh
41
+ $ bundle install
42
+ ```
43
+
44
+ 4. Install the Google Cloud dependencies.
45
+
46
+ ```sh
47
+ $ cd google-cloud-errors/
48
+ $ bundle exec rake bundleupdate
49
+ ```
50
+
51
+ ## Console
52
+
53
+ In order to run code interactively, you can automatically load
54
+ google-cloud and its dependencies in IRB. This requires that your
55
+ developer environment has already been configured by following the steps
56
+ described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
57
+ can be created with:
58
+
59
+ ```sh
60
+ $ cd google-cloud-errors/
61
+ $ bundle exec rake console
62
+ ```
63
+
64
+ ## Google Cloud Tests
65
+
66
+ Tests are very important part of google-cloud. All contributions
67
+ should include tests that ensure the contributed code behaves as expected.
68
+
69
+ To run the unit tests, documentation tests, and code style checks together for a
70
+ package:
71
+
72
+ ``` sh
73
+ $ cd google-cloud-errors/
74
+ $ bundle exec rake ci
75
+ ```
76
+
77
+ To run the command above, plus all acceptance tests, use `rake ci:acceptance` or
78
+ its handy alias, `rake ci:a`.
79
+
80
+ ### Google Cloud Unit Tests
81
+
82
+
83
+ The project uses the [minitest](https://github.com/seattlerb/minitest) library,
84
+ including [specs](https://github.com/seattlerb/minitest#specs),
85
+ [mocks](https://github.com/seattlerb/minitest#mocks) and
86
+ [minitest-autotest](https://github.com/seattlerb/minitest-autotest).
87
+
88
+ To run the Google Cloud unit tests:
89
+
90
+ ``` sh
91
+ $ cd google-cloud-errors/
92
+ $ bundle exec rake test
93
+ ```
94
+
95
+ ### Google Cloud Documentation Tests
96
+
97
+ The project tests the code examples in the gem's
98
+ [YARD](https://github.com/lsegal/yard)-based documentation.
99
+
100
+ The example testing functions in a way that is very similar to unit testing, and
101
+ in fact the library providing it,
102
+ [yard-doctest](https://github.com/p0deje/yard-doctest), is based on the
103
+ project's unit test library, [minitest](https://github.com/seattlerb/minitest).
104
+
105
+ To run the Google Cloud documentation tests:
106
+
107
+ ``` sh
108
+ $ cd google-cloud-errors/
109
+ $ bundle exec rake doctest
110
+ ```
111
+
112
+ If you add, remove or modify documentation examples when working on a pull
113
+ request, you may need to update the setup for the tests. The stubs and mocks
114
+ required to run the tests are located in `support/doctest_helper.rb`. Please
115
+ note that much of the setup is matched by the title of the
116
+ [`@example`](http://www.rubydoc.info/gems/yard/file/docs/Tags.md#example) tag.
117
+ If you alter an example's title, you may encounter breaking tests.
118
+
119
+ ## Coding Style
120
+
121
+ Please follow the established coding style in the library. The style is is
122
+ largely based on [The Ruby Style
123
+ Guide](https://github.com/bbatsov/ruby-style-guide) with a few exceptions based
124
+ on seattle-style:
125
+
126
+ * Avoid parenthesis when possible, including in method definitions.
127
+ * Always use double quotes strings. ([Option
128
+ B](https://github.com/bbatsov/ruby-style-guide#strings))
129
+
130
+ You can check your code against these rules by running Rubocop like so:
131
+
132
+ ```sh
133
+ $ cd google-cloud-errors/
134
+ $ bundle exec rake rubocop
135
+ ```
136
+
137
+ ## Code of Conduct
138
+
139
+ Please note that this project is released with a Contributor Code of Conduct. By
140
+ participating in this project you agree to abide by its terms. See
141
+ {file:CODE_OF_CONDUCT.md Code of Conduct} for more information.
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ https://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # google-cloud-errors
2
+
3
+ This library contains error classes raised by Google Cloud API clients.
4
+ Please see the
5
+ [GitHub repository](https://github.com/googleapis/google-cloud-ruby) for more
6
+ information about Google Cloud gems.
7
+
8
+ - [google-cloud-errors API documentation](https://googleapis.dev/ruby/google-cloud-errors/latest)
9
+
10
+ ## Supported Ruby Versions
11
+
12
+ This library is supported on Ruby 2.4+.
13
+
14
+ Google provides official support for Ruby versions that are actively supported
15
+ by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
16
+ security maintenance, and not end of life. Currently, this means Ruby 2.4 and
17
+ later. Older versions of Ruby _may_ still work, but are unsupported and not
18
+ recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
19
+ about the Ruby support schedule.
20
+
21
+ ## Versioning
22
+
23
+ This library follows [Semantic Versioning](http://semver.org/).
24
+
25
+ It is currently in major version zero (0.y.z), which means that anything may
26
+ change at any time and the public API should not be considered stable.
27
+
28
+ ## Contributing
29
+
30
+ Contributions to this library are always welcome and highly encouraged.
31
+
32
+ See the
33
+ [Contributing Guide](https://googleapis.dev/ruby/google-cloud-errors/latest/file.CONTRIBUTING.html)
34
+ for more information on how to get started.
35
+
36
+ Please note that this project is released with a Contributor Code of Conduct. By
37
+ participating in this project you agree to abide by its terms. See
38
+ [Code of Conduct](https://googleapis.dev/ruby/google-cloud-errors/latest/file.CODE_OF_CONDUCT.html)
39
+ for more information.
40
+
41
+ ## License
42
+
43
+ This library is licensed under Apache 2.0. Full license text is available in
44
+ [LICENSE](https://googleapis.dev/ruby/google-cloud-errors/latest/file.LICENSE.html).
45
+
46
+ ## Support
47
+
48
+ Please report bugs
49
+ [on Github](https://github.com/googleapis/google-cloud-ruby/issues).
50
+ Don't hesitate to
51
+ [ask questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
52
+ about the client or APIs on [StackOverflow](http://stackoverflow.com).
@@ -0,0 +1,17 @@
1
+ # Copyright 2019 Google LLC
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
+ # https://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
+
16
+ require "google/cloud/errors"
17
+ require "google/cloud/errors/version"
@@ -0,0 +1,312 @@
1
+ # Copyright 2015 Google LLC
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
+ # https://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
+
16
+ require "English"
17
+
18
+ module Google
19
+ module Cloud
20
+ ##
21
+ # Base google-cloud exception class.
22
+ class Error < StandardError
23
+ ##
24
+ # Construct a new Google::Cloud::Error object, optionally passing in a
25
+ # message.
26
+ def initialize msg = nil
27
+ super
28
+ end
29
+
30
+ ##
31
+ # Returns the value of `status_code` from the underlying cause error
32
+ # object, if both are present. Otherwise returns `nil`.
33
+ #
34
+ # This is typically present on errors originating from calls to an API
35
+ # over HTTP/REST.
36
+ #
37
+ # @return [Object, nil]
38
+ def status_code
39
+ return nil unless cause&.respond_to? :status_code
40
+ cause.status_code
41
+ end
42
+
43
+ ##
44
+ # Returns the value of `body` from the underlying cause error
45
+ # object, if both are present. Otherwise returns `nil`.
46
+ #
47
+ # This is typically present on errors originating from calls to an API
48
+ # over HTTP/REST.
49
+ #
50
+ # @return [Object, nil]
51
+ def body
52
+ return nil unless cause&.respond_to? :body
53
+ cause.body
54
+ end
55
+
56
+ ##
57
+ # Returns the value of `header` from the underlying cause error
58
+ # object, if both are present. Otherwise returns `nil`.
59
+ #
60
+ # This is typically present on errors originating from calls to an API
61
+ # over HTTP/REST.
62
+ #
63
+ # @return [Object, nil]
64
+ def header
65
+ return nil unless cause&.respond_to? :header
66
+ cause.header
67
+ end
68
+
69
+ ##
70
+ # Returns the value of `code` from the underlying cause error
71
+ # object, if both are present. Otherwise returns `nil`.
72
+ #
73
+ # This is typically present on errors originating from calls to an API
74
+ # over gRPC.
75
+ #
76
+ # @return [Object, nil]
77
+ def code
78
+ return nil unless cause&.respond_to? :code
79
+ cause.code
80
+ end
81
+
82
+ ##
83
+ # Returns the value of `details` from the underlying cause error
84
+ # object, if both are present. Otherwise returns `nil`.
85
+ #
86
+ # This is typically present on errors originating from calls to an API
87
+ # over gRPC.
88
+ #
89
+ # @return [Object, nil]
90
+ def details
91
+ return nil unless cause&.respond_to? :details
92
+ cause.details
93
+ end
94
+
95
+ ##
96
+ # Returns the value of `metadata` from the underlying cause error
97
+ # object, if both are present. Otherwise returns `nil`.
98
+ #
99
+ # This is typically present on errors originating from calls to an API
100
+ # over gRPC.
101
+ #
102
+ # @return [Object, nil]
103
+ def metadata
104
+ return nil unless cause&.respond_to? :metadata
105
+ cause.metadata
106
+ end
107
+
108
+ ##
109
+ # Returns the value of `status_details` from the underlying cause error
110
+ # object, if both are present. Otherwise returns `nil`.
111
+ #
112
+ # This is typically present on errors originating from calls to an API
113
+ # over gRPC.
114
+ #
115
+ # @return [Object, nil]
116
+ def status_details
117
+ return nil unless cause&.respond_to? :status_details
118
+ cause.status_details
119
+ end
120
+
121
+ # @private Create a new error object from a client error
122
+ def self.from_error error
123
+ klass = if error.respond_to? :code
124
+ grpc_error_class_for error.code
125
+ elsif error.respond_to? :status_code
126
+ gapi_error_class_for error.status_code
127
+ else
128
+ self
129
+ end
130
+ klass.new error.message
131
+ end
132
+
133
+ # @private Identify the subclass for a gRPC error
134
+ def self.grpc_error_class_for grpc_error_code
135
+ # The gRPC status code 0 is for a successful response.
136
+ # So there is no error subclass for a 0 status code, use current class.
137
+ [
138
+ self, CanceledError, UnknownError, InvalidArgumentError,
139
+ DeadlineExceededError, NotFoundError, AlreadyExistsError,
140
+ PermissionDeniedError, ResourceExhaustedError,
141
+ FailedPreconditionError, AbortedError, OutOfRangeError,
142
+ UnimplementedError, InternalError, UnavailableError, DataLossError,
143
+ UnauthenticatedError
144
+ ][grpc_error_code] || self
145
+ end
146
+
147
+ # @private Identify the subclass for a Google API Client error
148
+ def self.gapi_error_class_for http_status_code
149
+ # The http status codes mapped to their error classes.
150
+ {
151
+ 400 => InvalidArgumentError, # FailedPreconditionError/OutOfRangeError
152
+ 401 => UnauthenticatedError,
153
+ 403 => PermissionDeniedError,
154
+ 404 => NotFoundError,
155
+ 409 => AlreadyExistsError, # AbortedError
156
+ 412 => FailedPreconditionError,
157
+ 429 => ResourceExhaustedError,
158
+ 499 => CanceledError,
159
+ 500 => InternalError, # UnknownError/DataLossError
160
+ 501 => UnimplementedError,
161
+ 503 => UnavailableError,
162
+ 504 => DeadlineExceededError
163
+ }[http_status_code] || self
164
+ end
165
+ end
166
+
167
+ ##
168
+ # Canceled indicates the operation was cancelled (typically by the caller).
169
+ class CanceledError < Error
170
+ end
171
+
172
+ ##
173
+ # Unknown error. An example of where this error may be returned is
174
+ # if a Status value received from another address space belongs to
175
+ # an error-space that is not known in this address space. Also
176
+ # errors raised by APIs that do not return enough error information
177
+ # may be converted to this error.
178
+ class UnknownError < Error
179
+ end
180
+
181
+ ##
182
+ # InvalidArgument indicates client specified an invalid argument.
183
+ # Note that this differs from FailedPrecondition. It indicates arguments
184
+ # that are problematic regardless of the state of the system
185
+ # (e.g., a malformed file name).
186
+ class InvalidArgumentError < Error
187
+ end
188
+
189
+ ##
190
+ # DeadlineExceeded means operation expired before completion.
191
+ # For operations that change the state of the system, this error may be
192
+ # returned even if the operation has completed successfully. For
193
+ # example, a successful response from a server could have been delayed
194
+ # long enough for the deadline to expire.
195
+ class DeadlineExceededError < Error
196
+ end
197
+
198
+ ##
199
+ # NotFound means some requested entity (e.g., file or directory) was
200
+ # not found.
201
+ class NotFoundError < Error
202
+ end
203
+
204
+ ##
205
+ # AlreadyExists means an attempt to create an entity failed because one
206
+ # already exists.
207
+ class AlreadyExistsError < Error
208
+ end
209
+
210
+ ##
211
+ # PermissionDenied indicates the caller does not have permission to
212
+ # execute the specified operation. It must not be used for rejections
213
+ # caused by exhausting some resource (use ResourceExhausted
214
+ # instead for those errors). It must not be
215
+ # used if the caller cannot be identified (use Unauthenticated
216
+ # instead for those errors).
217
+ class PermissionDeniedError < Error
218
+ end
219
+
220
+ ##
221
+ # Unauthenticated indicates the request does not have valid
222
+ # authentication credentials for the operation.
223
+ class UnauthenticatedError < Error
224
+ end
225
+
226
+ ##
227
+ # ResourceExhausted indicates some resource has been exhausted, perhaps
228
+ # a per-user quota, or perhaps the entire file system is out of space.
229
+ class ResourceExhaustedError < Error
230
+ end
231
+
232
+ ##
233
+ # FailedPrecondition indicates operation was rejected because the
234
+ # system is not in a state required for the operation's execution.
235
+ # For example, directory to be deleted may be non-empty, an rmdir
236
+ # operation is applied to a non-directory, etc.
237
+ #
238
+ # A litmus test that may help a service implementor in deciding
239
+ # between FailedPrecondition, Aborted, and Unavailable:
240
+ # (a) Use Unavailable if the client can retry just the failing call.
241
+ # (b) Use Aborted if the client should retry at a higher-level
242
+ # (e.g., restarting a read-modify-write sequence).
243
+ # (c) Use FailedPrecondition if the client should not retry until
244
+ # the system state has been explicitly fixed. E.g., if an "rmdir"
245
+ # fails because the directory is non-empty, FailedPrecondition
246
+ # should be returned since the client should not retry unless
247
+ # they have first fixed up the directory by deleting files from it.
248
+ # (d) Use FailedPrecondition if the client performs conditional
249
+ # REST Get/Update/Delete on a resource and the resource on the
250
+ # server does not match the condition. E.g., conflicting
251
+ # read-modify-write on the same resource.
252
+ class FailedPreconditionError < Error
253
+ end
254
+
255
+ ##
256
+ # Aborted indicates the operation was aborted, typically due to a
257
+ # concurrency issue like sequencer check failures, transaction aborts,
258
+ # etc.
259
+ #
260
+ # See litmus test above for deciding between FailedPrecondition,
261
+ # Aborted, and Unavailable.
262
+ class AbortedError < Error
263
+ end
264
+
265
+ ##
266
+ # OutOfRange means operation was attempted past the valid range.
267
+ # E.g., seeking or reading past end of file.
268
+ #
269
+ # Unlike InvalidArgument, this error indicates a problem that may
270
+ # be fixed if the system state changes. For example, a 32-bit file
271
+ # system will generate InvalidArgument if asked to read at an
272
+ # offset that is not in the range [0,2^32-1], but it will generate
273
+ # OutOfRange if asked to read from an offset past the current
274
+ # file size.
275
+ #
276
+ # There is a fair bit of overlap between FailedPrecondition and
277
+ # OutOfRange. We recommend using OutOfRange (the more specific
278
+ # error) when it applies so that callers who are iterating through
279
+ # a space can easily look for an OutOfRange error to detect when
280
+ # they are done.
281
+ class OutOfRangeError < Error
282
+ end
283
+
284
+ ##
285
+ # Unimplemented indicates operation is not implemented or not
286
+ # supported/enabled in this service.
287
+ class UnimplementedError < Error
288
+ end
289
+
290
+ ##
291
+ # Internal errors. Means some invariants expected by underlying
292
+ # system has been broken. If you see one of these errors,
293
+ # something is very broken.
294
+ class InternalError < Error
295
+ end
296
+
297
+ ##
298
+ # Unavailable indicates the service is currently unavailable.
299
+ # This is a most likely a transient condition and may be corrected
300
+ # by retrying with a backoff.
301
+ #
302
+ # See litmus test above for deciding between FailedPrecondition,
303
+ # Aborted, and Unavailable.
304
+ class UnavailableError < Error
305
+ end
306
+
307
+ ##
308
+ # DataLoss indicates unrecoverable data loss or corruption.
309
+ class DataLossError < Error
310
+ end
311
+ end
312
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright 2016 Google LLC
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
+ # https://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
+
16
+ module Google
17
+ module Cloud
18
+ module Errors
19
+ VERSION = "0.0.1".freeze
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-cloud-errors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Moore
8
+ - Chris Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-12-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: autotest-suffix
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.1'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: google-style
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 1.24.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.24.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.10'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '5.10'
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest-autotest
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: minitest-focus
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.1'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.1'
84
+ - !ruby/object:Gem::Dependency
85
+ name: minitest-rg
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '5.2'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '5.2'
98
+ - !ruby/object:Gem::Dependency
99
+ name: redcarpet
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '3.0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '3.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: simplecov
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '0.9'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '0.9'
126
+ - !ruby/object:Gem::Dependency
127
+ name: yard
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '0.9'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.9'
140
+ - !ruby/object:Gem::Dependency
141
+ name: yard-doctest
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: 0.1.13
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: 0.1.13
154
+ description: google-cloud-errors defines error classes for google-cloud-ruby.
155
+ email:
156
+ - mike@blowmage.com
157
+ - quartzmo@gmail.com
158
+ executables: []
159
+ extensions: []
160
+ extra_rdoc_files: []
161
+ files:
162
+ - ".yardopts"
163
+ - CODE_OF_CONDUCT.md
164
+ - CONTRIBUTING.md
165
+ - LICENSE
166
+ - README.md
167
+ - lib/google-cloud-errors.rb
168
+ - lib/google/cloud/errors.rb
169
+ - lib/google/cloud/errors/version.rb
170
+ homepage: https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-errors
171
+ licenses:
172
+ - Apache-2.0
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '2.4'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubygems_version: 3.1.2
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Error classes for google-cloud-ruby
193
+ test_files: []