Skip to content

Commit 4f6c9ba

Browse files
committed
Add op-map to ex-data when CreateChangeSet fails
1 parent 6c9aed0 commit 4f6c9ba

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Unreleased
22

33
- Add stack name to "creating change-set" log message.
4+
- Add op-map to ex-data when CreateChangeSet fails.
45

56
## v0.26.0 (2025-03-31)
67

src/salmon/cloudformation.clj

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@
200200
(fn [signal]
201201
(validate! signal :pre? true))})
202202

203-
(defn- response-error [message response]
203+
(defn- response-error [message response & [extra-ex-data]]
204204
(ex-info (str message
205205
(some->> response u/aws-error-message (str ": ")))
206-
{:response response}))
206+
(assoc extra-ex-data :response response)))
207207

208208
(defn- aws-parameters [parameters]
209209
(mapv
@@ -649,14 +649,22 @@
649649
:Tags (u/tags tags)
650650
(if json :TemplateBody :TemplateURL) (or json url)}
651651
_ (logr/info "Creating change-set" name "for stack" stack-name)
652-
r (aws/invoke client {:op :CreateChangeSet :request request})]
653-
(if (and (u/anomaly? r)
654-
(= "ValidationError" (u/aws-error-code r))
655-
(str/includes? (u/aws-error-message r) "does not exist"))
652+
op-map {:op :CreateChangeSet :request request}
653+
r (aws/invoke client op-map)]
654+
(cond
655+
(not (u/anomaly? r))
656+
r
657+
658+
(and
659+
(= "ValidationError" (u/aws-error-code r))
660+
(str/includes? (u/aws-error-message r) "does not exist"))
656661
(aws/invoke client
657662
{:op :CreateChangeSet
658663
:request (assoc request :ChangeSetType "CREATE")})
659-
r)))
664+
665+
:else
666+
(throw (response-error "Error creating change set" r
667+
op-map)))))
660668

661669
(defn- start-change-set! [{::ds/keys [config instance]
662670
:as signal}]
@@ -667,19 +675,17 @@
667675
(let [_ (validate! signal)
668676
client (or (:client config)
669677
(aws/client {:api :cloudformation :region region}))
670-
{:as r :keys [Id StackId]}
678+
{:keys [Id StackId]}
671679
#__ (create-change-set! client signal (template-data config :template template :validate? false))]
672-
(if (u/anomaly? r)
673-
(throw (response-error "Error creating change set" r))
674-
(let [{:keys [Changes]}
675-
#__ (wait-until-complete-change-set! Id StackId client
676-
:fail-on-no-changes? fail-on-no-changes?)]
677-
{:changes Changes
678-
:client client
679-
:id Id
680-
:name name
681-
:stack-id StackId
682-
:stack-name stack-name}))))))
680+
(let [{:keys [Changes]}
681+
#__ (wait-until-complete-change-set! Id StackId client
682+
:fail-on-no-changes? fail-on-no-changes?)]
683+
{:changes Changes
684+
:client client
685+
:id Id
686+
:name name
687+
:stack-id StackId
688+
:stack-name stack-name})))))
683689

684690
(defn- delete-change-set!
685691
[{:keys [::ds/instance]

0 commit comments

Comments
 (0)