Skip to content

Commit 4e14eb8

Browse files
committed
fix: Handle properties of mixed content and repeated values
1 parent a94f6b0 commit 4e14eb8

File tree

6 files changed

+1945
-1572
lines changed

6 files changed

+1945
-1572
lines changed

lib/appmap/value_inspector.rb

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@ def detect_size(value)
1414
def detect_schema(value, max_depth: MAX_DEPTH, type_info: {}, observed_values: Set.new(), depth: 0)
1515
return type_info if depth == max_depth
1616

17-
begin
18-
if value.respond_to?(:keys)
19-
properties = value.keys.select { |key| key != '' && !key.nil? }.map do |key|
20-
next_value = value[key]
21-
next if observed_values.include?(next_value)
22-
23-
observed_values << next_value
24-
{ name: key, class: best_class_name(next_value) }.tap do |schema|
25-
detect_schema(next_value, **{ max_depth: max_depth, type_info: schema, observed_values: observed_values, depth: depth + 1 })
17+
if value.respond_to?(:keys)
18+
return if observed_values.include?(value.object_id)
19+
20+
observed_values << value.object_id
21+
22+
properties = value.keys.select { |key| key != "" && !key.nil? }.map do |key|
23+
next_value = value[key]
24+
25+
value_schema = begin
26+
{ name: key, class: best_class_name(next_value) }
27+
rescue
28+
warn "Error in add_schema(#{next_value.class})", $!
29+
raise
2630
end
27-
end.compact
28-
type_info[:properties] = properties unless properties.empty?
29-
elsif value.respond_to?(:first) && !observed_values.include?(value.first)
30-
observed_values << value.first
31-
detect_schema(value.first, **{ max_depth: max_depth, type_info: type_info, observed_values: observed_values, depth: depth + 1 })
32-
end
33-
rescue
34-
warn "Error in add_schema(#{value.class})", $!
35-
raise
31+
32+
detect_schema(next_value, **{ max_depth: max_depth, type_info: value_schema, observed_values: observed_values, depth: depth + 1 })
33+
end.compact
34+
type_info[:properties] = properties unless properties.empty?
35+
elsif value.respond_to?(:first)
36+
detect_schema(value.first, **{ max_depth: max_depth, type_info: type_info, observed_values: observed_values, depth: depth + 1 })
3637
end
3738
type_info
3839
end
@@ -43,7 +44,7 @@ def best_class_name(value)
4344
while value_cls && value_cls.name.nil?
4445
value_cls = value_cls.superclass
4546
end
46-
value_cls&.name || 'unknown'
47+
value_cls&.name || "unknown"
4748
end
4849
end
4950
end

0 commit comments

Comments
 (0)