Skip to content

Commit f8218cb

Browse files
c0d1ngm0nk3ynicolasbenderpbusko
committed
Enhance error mapping (#302)
* Add cnb error to sanitizer Co-authored-by: Ralf Pannemans <[email protected]> * add staging failure reasons to models Co-authored-by: Pavel Busko <[email protected]> * move cnb exit codes to 230 range Co-authored-by: Nicolas Bender <[email protected]> * fix cnb logging prefix for staging completion Co-authored-by: Pavel Busko <[email protected]> * Update spec/unit/lib/cloud_controller/diego/failure_reason_sanitizer_spec.rb --------- Co-authored-by: Nicolas Bender <[email protected]> Co-authored-by: Pavel Busko <[email protected]> Co-authored-by: Pavel Busko <[email protected]>
1 parent ebfa6ee commit f8218cb

File tree

6 files changed

+82
-10
lines changed

6 files changed

+82
-10
lines changed

app/models/runtime/build_model.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class BuildModel < Sequel::Model(:builds)
1313
STAGED_STATE
1414
].freeze
1515
STAGING_FAILED_REASONS = %w[StagerError StagingError StagingTimeExpired NoAppDetectedError BuildpackCompileFailed
16-
BuildpackReleaseFailed InsufficientResources NoCompatibleCell].map(&:freeze).freeze
16+
BuildpackReleaseFailed InsufficientResources NoCompatibleCell
17+
CNBGenericBuildFailed CNBDownloadBuildpackFailed CNBDetectFailed CNBBuildFailed CNBExportFailed CNBLaunchFailed].map(&:freeze).freeze
1718

1819
many_to_one :app,
1920
class: 'VCAP::CloudController::AppModel',

app/models/runtime/droplet_model.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class DropletModel < Sequel::Model(:droplets)
1717
EXPIRED_STATE
1818
].freeze
1919
STAGING_FAILED_REASONS = %w[StagerError StagingError StagingTimeExpired NoAppDetectedError BuildpackCompileFailed
20-
BuildpackReleaseFailed InsufficientResources NoCompatibleCell].map(&:freeze).freeze
20+
BuildpackReleaseFailed InsufficientResources NoCompatibleCell
21+
CNBGenericBuildFailed CNBDownloadBuildpackFailed CNBDetectFailed CNBBuildFailed CNBExportFailed CNBLaunchFailed].map(&:freeze).freeze
2122

2223
many_to_one :package, class: 'VCAP::CloudController::PackageModel', key: :package_guid, primary_key: :guid, without_guid_generation: true
2324
many_to_one :app, class: 'VCAP::CloudController::AppModel', key: :app_guid, primary_key: :guid, without_guid_generation: true

errors/v2.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,3 +1363,33 @@
13631363
name: DeserializationError
13641364
http_code: 500
13651365
message: "%s"
1366+
1367+
430001:
1368+
name: CNBGenericBuildFailed
1369+
http_code: 400
1370+
message: "cnb: generic build failure"
1371+
1372+
430002:
1373+
name: CNBDownloadBuildpackFailed
1374+
http_code: 400
1375+
message: "cnb: downloading buildpacks failed"
1376+
1377+
430003:
1378+
name: CNBDetectFailed
1379+
http_code: 400
1380+
message: "cnb: detecting failed"
1381+
1382+
430004:
1383+
name: CNBBuildFailed
1384+
http_code: 400
1385+
message: "cnb: building failed"
1386+
1387+
430005:
1388+
name: CNBExportFailed
1389+
http_code: 400
1390+
message: "cnb: exporting failed"
1391+
1392+
430006:
1393+
name: CNBLaunchFailed
1394+
http_code: 400
1395+
message: "cnb: launching failed"

lib/cloud_controller/diego/cnb/staging_completion_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Diego
66
module CNB
77
class StagingCompletionHandler < VCAP::CloudController::Diego::StagingCompletionHandler
88
def logger_prefix
9-
'diego.staging.buildpack.'
9+
'diego.staging.cnb.'
1010
end
1111

1212
def self.schema

lib/cloud_controller/diego/failure_reason_sanitizer.rb

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
module VCAP::CloudController
22
module Diego
33
module CCMessages
4-
STAGING_ERROR = 'StagingError'.freeze
5-
INSUFFICIENT_RESOURCES = 'InsufficientResources'.freeze
6-
NO_COMPATIBLE_CELL = 'NoCompatibleCell'.freeze
7-
CELL_COMMUNICATION_ERROR = 'CellCommunicationError'.freeze
8-
BUILDPACK_DETECT_FAILED = 'NoAppDetectedError'.freeze
9-
BUILDPACK_COMPILE_FAILED = 'BuildpackCompileFailed'.freeze
10-
BUILDPACK_RELEASE_FAILED = 'BuildpackReleaseFailed'.freeze
4+
STAGING_ERROR = 'StagingError'.freeze
5+
INSUFFICIENT_RESOURCES = 'InsufficientResources'.freeze
6+
NO_COMPATIBLE_CELL = 'NoCompatibleCell'.freeze
7+
CELL_COMMUNICATION_ERROR = 'CellCommunicationError'.freeze
8+
BUILDPACK_DETECT_FAILED = 'NoAppDetectedError'.freeze
9+
BUILDPACK_COMPILE_FAILED = 'BuildpackCompileFailed'.freeze
10+
BUILDPACK_RELEASE_FAILED = 'BuildpackReleaseFailed'.freeze
11+
CNB_GENERIC_BUILD_FAILED = 'CNBGenericBuildFailed'.freeze
12+
CNB_DOWNLOAD_BUILDPACK_FAILED = 'CNBDownloadBuildpackFailed'.freeze
13+
CNB_DETECTING_FAILED = 'CNBDetectFailed'.freeze
14+
CNB_BUILDING_FAILED = 'CNBBuildFailed'.freeze
15+
CNB_EXPORTING_FAILED = 'CNBExportFailed'.freeze
16+
CNB_LAUNCHING_FAILED = 'CNBLaunchFailed'.freeze
1117
end
1218

1319
module DiegoErrors
@@ -37,6 +43,24 @@ def self.sanitize(message)
3743
elsif message.ends_with?('224')
3844
id = CCMessages::BUILDPACK_RELEASE_FAILED
3945
message = staging_failed
46+
elsif message.ends_with?('231')
47+
id = CCMessages::CNB_GENERIC_BUILD_FAILED
48+
message = staging_failed
49+
elsif message.ends_with?('232')
50+
id = CCMessages::CNB_DOWNLOAD_BUILDPACK_FAILED
51+
message = staging_failed
52+
elsif message.ends_with?('233')
53+
id = CCMessages::CNB_DETECTING_FAILED
54+
message = staging_failed
55+
elsif message.ends_with?('234')
56+
id = CCMessages::CNB_BUILDING_FAILED
57+
message = staging_failed
58+
elsif message.ends_with?('235')
59+
id = CCMessages::CNB_EXPORTING_FAILED
60+
message = staging_failed
61+
elsif message.ends_with?('236')
62+
id = CCMessages::CNB_LAUNCHING_FAILED
63+
message = staging_failed
4064
elsif message.starts_with?(DiegoErrors::INSUFFICIENT_RESOURCES_MESSAGE)
4165
id = CCMessages::INSUFFICIENT_RESOURCES
4266
elsif message.starts_with?(DiegoErrors::CELL_MISMATCH_MESSAGE)

spec/unit/lib/cloud_controller/diego/failure_reason_sanitizer_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ module Diego
7474
expect(staging_error[:message]).to eq('staging failed')
7575
end
7676
end
77+
78+
context 'Handles specific return codes' do
79+
it 'returns specific message for buildpack lifecycle rc' do
80+
staging_error = FailureReasonSanitizer.sanitize('exit status 222')
81+
expect(staging_error[:id]).to eq(CCMessages::BUILDPACK_DETECT_FAILED)
82+
expect(staging_error[:message]).to eq('staging failed')
83+
end
84+
85+
it 'returns specific message for cnb lifecycle rc' do
86+
staging_error = FailureReasonSanitizer.sanitize('exit status 233')
87+
expect(staging_error[:id]).to eq(CCMessages::CNB_DETECTING_FAILED)
88+
expect(staging_error[:message]).to eq('staging failed')
89+
end
90+
91+
end
92+
7793
end
7894
end
7995
end

0 commit comments

Comments
 (0)