Skip to content

Commit

Permalink
fix(resources): Publish pipeline should ignore ENOCHANGES
Browse files Browse the repository at this point in the history
Some changes may result in the pipeline not having any changes to
publish. This will be an error from the server that the
`publish_pipeline` resource should ignore.

Ref: LOG-20073
  • Loading branch information
darinspivey committed Jun 10, 2024
1 parent cbd1077 commit 79b713d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
20.12.2

10 changes: 5 additions & 5 deletions internal/client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ type validationError struct {
Path string `json:"instancePath,omitempty"`
Message string `json:"message,omitempty"`
}
type apiResponseError struct {
type ApiResponseError struct {
Message string `json:"message"`
Code string `json:"code,omitempty"`
Status uint16 `json:"status"`
Errors []validationError `json:"errors,omitempty"`
}

func newAPIError(status int, bodyBuffer []byte, _ context.Context) apiResponseError {
result := apiResponseError{
func newAPIError(status int, bodyBuffer []byte, _ context.Context) ApiResponseError {
result := ApiResponseError{
Status: uint16(status),
}
if len(bodyBuffer) == 0 {
Expand All @@ -34,7 +34,7 @@ func newAPIError(status int, bodyBuffer []byte, _ context.Context) apiResponseEr
}

// implement errors.Error interface
func (e apiResponseError) Error() string {
func (e ApiResponseError) Error() string {
errString := fmt.Sprintf("%d %s: %s", e.Status, e.Code, e.Message)
if len(e.Errors) > 0 {
errors := make([]validationError, 0)
Expand Down Expand Up @@ -64,7 +64,7 @@ func JSONMarshal(t any) ([]byte, error) {
}

func IsNotFoundError(target error) bool {
err, ok := target.(apiResponseError)
err, ok := target.(ApiResponseError)
return ok && err.Status == http.StatusNotFound
}

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/publish_pipeline_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (r *PublishPipelineResource) Create(ctx context.Context, req resource.Creat
// and sees that the `updated_at` timestamp has changed on the server.
_, err := r.client.PublishPipeline(publish.PipelineId, ctx)

if err != nil {
if err != nil && err.(client.ApiResponseError).Code != "ENOCHANGES" {
resp.Diagnostics.AddError(
"Error publishing pipeline",
"Could not publish pipeline, unexpected error: "+err.Error(),
Expand Down

0 comments on commit 79b713d

Please sign in to comment.