Skip to content

Commit d1de45d

Browse files
committed
Handle failed metafield creation with context
Enhances error handling for metafield creation failures.
1 parent 21b9b24 commit d1de45d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/shopify_toolkit/metafield_statements.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@ def create_metafield(owner_type, key, type, namespace: :custom, name:, **options
2323

2424
# Process validations to convert metaobject types to GIDs (only for metaobject reference fields)
2525
if options[:validations] && is_metaobject_reference_type?(type)
26-
options[:validations] = convert_validations_types_to_gids(options[:validations])
26+
begin
27+
options[:validations] = convert_validations_types_to_gids(options[:validations])
28+
rescue RuntimeError => e
29+
if e.message.include?("not found")
30+
say "ERROR: Cannot create metafield #{namespace}:#{key} - references non-existent metaobject. This suggests the metaobject was filtered out or failed to create."
31+
say " Original error: #{e.message}"
32+
return
33+
else
34+
raise e
35+
end
36+
end
2737
end
2838

2939
# Skip creation if metafield already exists

0 commit comments

Comments
 (0)