Skip to content

Commit 802a98b

Browse files
authored
Include route in error messages for manifest route updates (cloudfoundry#5026)
* fix: cloud_controller_ng#4971 * Apply review feedback
1 parent 35fe8b6 commit 802a98b

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

app/actions/manifest_route_update.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@ def update(app_guid, message, user_audit_info)
1818
app_guid => app
1919
}
2020
routes_to_map = []
21+
current_route = nil
2122

2223
message.manifest_route_mappings.each do |manifest_route_mapping|
24+
current_route = manifest_route_mapping[:route].to_s
2325
route = {
2426
model: find_or_create_valid_route(app, manifest_route_mapping[:route].to_hash, user_audit_info),
25-
protocol: manifest_route_mapping[:protocol]
27+
protocol: manifest_route_mapping[:protocol],
28+
route_string: current_route
2629
}
2730

28-
raise InvalidRoute.new("No domains exist for route #{manifest_route_mapping[:route]}") if route[:model].blank?
31+
raise InvalidRoute.new("No domains exist for route #{current_route}") if route[:model].blank?
2932

3033
routes_to_map << route
3134
end
3235

3336
# map route to app, but do this only if the full message contains valid routes
3437
routes_to_map.
3538
each do |route|
39+
current_route = route[:route_string]
3640
route_mapping = RouteMappingModel.find(app: app, route: route[:model])
3741
if route_mapping.nil?
3842
UpdateRouteDestinations.add(
@@ -53,7 +57,11 @@ def update(app_guid, message, user_audit_info)
5357
end
5458
end
5559
rescue Sequel::ValidationFailed, RouteCreate::Error, RouteUpdate::Error => e
56-
raise InvalidRoute.new(e.message)
60+
route_info = current_route ? "For route '#{current_route}': " : ''
61+
raise InvalidRoute.new("#{route_info}#{e.message}")
62+
rescue UpdateRouteDestinations::Error => e
63+
route_info = current_route ? "For route '#{current_route}': " : ''
64+
raise UpdateRouteDestinations::Error.new("#{route_info}#{e.message}")
5765
end
5866

5967
private

spec/unit/actions/manifest_route_update_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@ module VCAP::CloudController
312312
it 'throws an error' do
313313
expect do
314314
ManifestRouteUpdate.update(app.guid, message, user_audit_info)
315-
end.to raise_error(VCAP::CloudController::UpdateRouteDestinations::Error, 'Cannot use \'http2\' protocol for tcp routes; valid options are: [tcp].')
315+
end.to raise_error(
316+
VCAP::CloudController::UpdateRouteDestinations::Error,
317+
%r{For route 'http://tcp.tomato.avocado-toast.com:1234': Cannot use 'http2' protocol for tcp routes; valid options are: \[tcp\]}
318+
)
316319
end
317320
end
318321
end
@@ -492,7 +495,10 @@ module VCAP::CloudController
492495
it 'raises an error indicating hash_header is required' do
493496
expect do
494497
ManifestRouteUpdate.update(app.guid, message, user_audit_info)
495-
end.to raise_error(ManifestRouteUpdate::InvalidRoute, /Hash header must be present when loadbalancing is set to hash./)
498+
end.to raise_error(
499+
ManifestRouteUpdate::InvalidRoute,
500+
%r{For route 'http://potato.tomato.avocado-toast.com/some-path': Hash header must be present when loadbalancing is set to hash.}
501+
)
496502
end
497503
end
498504

0 commit comments

Comments
 (0)