google-gax 0.9.2 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/google/gax/errors.rb +18 -2
- data/lib/google/gax/version.rb +1 -1
- data/spec/google/gax/error_spec.rb +141 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 116098acb3407bbd5b01f92e330279b07b13caea
|
4
|
+
data.tar.gz: 24e05d6e466e28d51f895b472666b2b79785bfb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 139d012dfa865a1f7ea219c597f0b0d987d409cdd7a8db2b74b0e8fcbc2a96d9354d669882acb69378ef5461844f34e26905ef8df0069f63d35eb594a087f5f5
|
7
|
+
data.tar.gz: 75abafa5d443696e83494499b361dc0ff92c5b80c714e7fe4e359d9f88ff970f2c47a4d35e62cd43dbaaf9e4ed4486fd66d81127953bdf607fa3d058ca650e36
|
data/lib/google/gax/errors.rb
CHANGED
@@ -35,7 +35,7 @@ module Google
|
|
35
35
|
module Gax
|
36
36
|
# Common base class for exceptions raised by GAX.
|
37
37
|
class GaxError < StandardError
|
38
|
-
attr_reader :
|
38
|
+
attr_reader :status_details
|
39
39
|
|
40
40
|
# @param msg [String] describes the error that occurred.
|
41
41
|
def initialize(msg)
|
@@ -43,7 +43,8 @@ module Google
|
|
43
43
|
msg += ", caused by #{$ERROR_INFO}" if $ERROR_INFO
|
44
44
|
super(msg)
|
45
45
|
@cause = $ERROR_INFO
|
46
|
-
@
|
46
|
+
@status_details = \
|
47
|
+
Google::Gax::Grpc.deserialize_error_status_details(@cause)
|
47
48
|
end
|
48
49
|
|
49
50
|
# cause is a new method introduced in 2.1.0, bring this
|
@@ -53,6 +54,21 @@ module Google
|
|
53
54
|
@cause
|
54
55
|
end
|
55
56
|
end
|
57
|
+
|
58
|
+
def code
|
59
|
+
return nil unless cause && cause.respond_to?(:code)
|
60
|
+
cause.code
|
61
|
+
end
|
62
|
+
|
63
|
+
def details
|
64
|
+
return nil unless cause && cause.respond_to?(:details)
|
65
|
+
cause.details
|
66
|
+
end
|
67
|
+
|
68
|
+
def metadata
|
69
|
+
return nil unless cause && cause.respond_to?(:metadata)
|
70
|
+
cause.metadata
|
71
|
+
end
|
56
72
|
end
|
57
73
|
|
58
74
|
# Indicates an error during automatic GAX retrying.
|
data/lib/google/gax/version.rb
CHANGED
@@ -0,0 +1,141 @@
|
|
1
|
+
# Copyright 2017, Google Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are
|
6
|
+
# met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above
|
11
|
+
# copyright notice, this list of conditions and the following disclaimer
|
12
|
+
# in the documentation and/or other materials provided with the
|
13
|
+
# distribution.
|
14
|
+
# * Neither the name of Google Inc. nor the names of its
|
15
|
+
# contributors may be used to endorse or promote products derived from
|
16
|
+
# this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
|
30
|
+
require 'google/gax/errors'
|
31
|
+
require 'google/protobuf/any_pb'
|
32
|
+
require 'spec/fixtures/fixture_pb'
|
33
|
+
|
34
|
+
describe Google::Gax::GaxError do
|
35
|
+
describe 'without cause' do
|
36
|
+
it 'presents GRPC::BadStatus values' do
|
37
|
+
error = Google::Gax::GaxError.new('no cause')
|
38
|
+
|
39
|
+
expect(error).to be_an_instance_of(Google::Gax::GaxError)
|
40
|
+
expect(error.message).to eq('GaxError no cause')
|
41
|
+
expect(error.code).to be_nil
|
42
|
+
expect(error.details).to be_nil
|
43
|
+
expect(error.metadata).to be_nil
|
44
|
+
expect(error.status_details).to be_nil
|
45
|
+
|
46
|
+
expect(error.cause).to be_nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'with cause as RuntimeError' do
|
51
|
+
it 'presents GRPC::BadStatus values' do
|
52
|
+
error = wrapped_error('not allowed')
|
53
|
+
|
54
|
+
expect(error).to be_an_instance_of(Google::Gax::GaxError)
|
55
|
+
expect(error.message).to eq('GaxError not allowed, caused by not allowed')
|
56
|
+
expect(error.code).to be_nil
|
57
|
+
expect(error.details).to be_nil
|
58
|
+
expect(error.metadata).to be_nil
|
59
|
+
expect(error.status_details).to be_nil
|
60
|
+
|
61
|
+
expect(error.cause).to be_an_instance_of(RuntimeError)
|
62
|
+
expect(error.cause.message).to eq('not allowed')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'with cause as GRPC::BadStatus' do
|
67
|
+
it 'presents GRPC::BadStatus values' do
|
68
|
+
error = wrapped_badstatus(3, 'invalid')
|
69
|
+
|
70
|
+
expect(error).to be_an_instance_of(Google::Gax::GaxError)
|
71
|
+
expect(error.message).to eq('GaxError 3:invalid, caused by 3:invalid')
|
72
|
+
expect(error.code).to eq(3)
|
73
|
+
expect(error.details).to eq('invalid')
|
74
|
+
expect(error.metadata).to eq({})
|
75
|
+
expect(error.status_details).to eq(
|
76
|
+
'Could not parse error details due to a ' \
|
77
|
+
'malformed server response trailer.'
|
78
|
+
)
|
79
|
+
|
80
|
+
expect(error.cause).to be_an_instance_of(GRPC::BadStatus)
|
81
|
+
expect(error.cause.message).to eq('3:invalid')
|
82
|
+
expect(error.cause.code).to eq(3)
|
83
|
+
expect(error.cause.details).to eq('invalid')
|
84
|
+
expect(error.cause.metadata).to eq({})
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'with cause as GRPC::BadStatus with status_detail' do
|
89
|
+
it 'presents GRPC::BadStatus values' do
|
90
|
+
status_detail = debug_info('hello world')
|
91
|
+
encoded_status_detail = encoded_protobuf(status_detail)
|
92
|
+
metadata = { 'foo' => 'bar',
|
93
|
+
'grpc-status-details-bin' => encoded_status_detail }
|
94
|
+
error = wrapped_badstatus(1, 'cancelled', metadata)
|
95
|
+
|
96
|
+
expect(error).to be_an_instance_of(Google::Gax::GaxError)
|
97
|
+
expect(error.message).to eq('GaxError 1:cancelled, caused by 1:cancelled')
|
98
|
+
expect(error.code).to eq(1)
|
99
|
+
expect(error.details).to eq('cancelled')
|
100
|
+
expect(error.metadata).to eq(metadata)
|
101
|
+
expect(error.status_details).to eq([status_detail])
|
102
|
+
|
103
|
+
expect(error.cause).to be_an_instance_of(GRPC::BadStatus)
|
104
|
+
expect(error.cause.message).to eq('1:cancelled')
|
105
|
+
expect(error.cause.code).to eq(1)
|
106
|
+
expect(error.cause.details).to eq('cancelled')
|
107
|
+
expect(error.cause.metadata).to eq(metadata)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def wrap_with_gax_error(err)
|
112
|
+
raise err
|
113
|
+
rescue => e
|
114
|
+
raise Google::Gax::GaxError, e.message
|
115
|
+
end
|
116
|
+
|
117
|
+
def wrapped_error(msg)
|
118
|
+
wrap_with_gax_error(RuntimeError.new(msg))
|
119
|
+
rescue => gax_err
|
120
|
+
return gax_err
|
121
|
+
end
|
122
|
+
|
123
|
+
def debug_info(detail)
|
124
|
+
Google::Rpc::DebugInfo.new(detail: detail)
|
125
|
+
end
|
126
|
+
|
127
|
+
def encoded_protobuf(debug_info)
|
128
|
+
any = Google::Protobuf::Any.new
|
129
|
+
any.pack debug_info
|
130
|
+
|
131
|
+
Google::Rpc::Status.encode(
|
132
|
+
Google::Rpc::Status.new(details: [any])
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
def wrapped_badstatus(status, msg, metadata = {})
|
137
|
+
wrap_with_gax_error(GRPC::BadStatus.new(status, msg, metadata))
|
138
|
+
rescue => gax_err
|
139
|
+
return gax_err
|
140
|
+
end
|
141
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-gax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Google API Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: googleauth
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- spec/fixtures/fixture_pb.rb
|
188
188
|
- spec/google/gax/api_callable_spec.rb
|
189
189
|
- spec/google/gax/bundling_spec.rb
|
190
|
+
- spec/google/gax/error_spec.rb
|
190
191
|
- spec/google/gax/grpc_spec.rb
|
191
192
|
- spec/google/gax/operation_spec.rb
|
192
193
|
- spec/google/gax/path_template_spec.rb
|