Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
0df1e398
Commit
0df1e398
authored
Nov 20, 2015
by
Anders Carling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise NoMethodError for unknown fields
More informative and more ruby-like
parent
956a770a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
message.c
ruby/ext/google/protobuf_c/message.c
+1
-1
RubyMessage.java
.../src/main/java/com/google/protobuf/jruby/RubyMessage.java
+12
-0
basic.rb
ruby/tests/basic.rb
+12
-0
No files found.
ruby/ext/google/protobuf_c/message.c
View file @
0df1e398
...
...
@@ -166,7 +166,7 @@ VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
name
,
name_len
);
if
(
f
==
NULL
)
{
r
b_raise
(
rb_eArgError
,
"Unknown field"
);
r
eturn
rb_call_super
(
argc
,
argv
);
}
if
(
setter
)
{
...
...
ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java
View file @
0df1e398
...
...
@@ -217,6 +217,9 @@ public class RubyMessage extends RubyObject {
RubyDescriptor
rubyDescriptor
=
(
RubyDescriptor
)
getDescriptor
(
context
,
metaClass
);
IRubyObject
oneofDescriptor
=
rubyDescriptor
.
lookupOneof
(
context
,
args
[
0
]);
if
(
oneofDescriptor
.
isNil
())
{
if
(!
hasField
(
args
[
0
]))
{
throw
context
.
runtime
.
newNoMethodError
(
"undefined method `"
+
args
[
0
].
toString
()
+
"' for "
+
metaClass
.
toString
(),
args
[
0
].
asJavaString
(),
metaClass
);
}
return
index
(
context
,
args
[
0
]);
}
RubyOneofDescriptor
rubyOneofDescriptor
=
(
RubyOneofDescriptor
)
oneofDescriptor
;
...
...
@@ -233,6 +236,10 @@ public class RubyMessage extends RubyObject {
if
(
field
.
end_with_p
(
context
,
equalSign
).
isTrue
())
{
field
.
chomp_bang
(
context
,
equalSign
);
}
if
(!
hasField
(
field
))
{
throw
context
.
runtime
.
newNoMethodError
(
"undefined method `"
+
args
[
0
].
asJavaString
()
+
"' for "
+
metaClass
.
toString
(),
args
[
0
].
asJavaString
(),
metaClass
);
}
return
indexSet
(
context
,
field
,
args
[
1
]);
}
}
...
...
@@ -435,6 +442,11 @@ public class RubyMessage extends RubyObject {
return
ret
;
}
private
boolean
hasField
(
IRubyObject
fieldName
)
{
String
nameStr
=
fieldName
.
asJavaString
();
return
this
.
descriptor
.
findFieldByName
(
Utils
.
escapeIdentifier
(
nameStr
))
!=
null
;
}
private
void
checkRepeatedFieldType
(
ThreadContext
context
,
IRubyObject
value
,
Descriptors
.
FieldDescriptor
fieldDescriptor
)
{
Ruby
runtime
=
context
.
runtime
;
...
...
ruby/tests/basic.rb
View file @
0df1e398
...
...
@@ -191,6 +191,18 @@ module BasicTest
assert
m1
.
hash
!=
m2
.
hash
end
def
test_unknown_field_errors
e
=
assert_raise
NoMethodError
do
TestMessage
.
new
.
hello
end
assert_match
(
/hello/
,
e
.
message
)
e
=
assert_raise
NoMethodError
do
TestMessage
.
new
.
hello
=
"world"
end
assert_match
(
/hello/
,
e
.
message
)
end
def
test_type_errors
m
=
TestMessage
.
new
assert_raise
TypeError
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment