-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support partial resource initialization errors
This allows a provider to indicate that it tried to Create, Update or Read a resource but was not able atomically succeed, leaving the resource in a partially initialized state.
- Loading branch information
Showing
5 changed files
with
262 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
**/sdk | ||
|
||
examples/**/pulumi-resource-* | ||
examples/**/schema-*.json | ||
|
||
/.vscode | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2024, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package infer | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// An error indicating that the resource was created but failed to initialize. | ||
// | ||
// This error is treated specially in Create, Update and Read. If the returner error for a | ||
// Create, Update or Read returns true for Errors.Is, state is updated to correspond to | ||
// the accompanying state, the resource will be considered created, and the next call will | ||
// be Update with the new state. | ||
// | ||
// func (*Team) Create( | ||
// ctx p.Context, name string, input TeamInput, preview bool, | ||
// ) (id string, output TeamState, err error) { | ||
// team, err := GetConfig(ctx).Client.CreateTeam(ctx, | ||
// input.OrganizationName, input.Name, | ||
// input.TeamType, input.DisplayName, | ||
// input.Description, input.GithubTeamId) | ||
// if err != nil { | ||
// return "", TeamState{}, fmt.Errorf("error creating team '%s': %w", input.Name, err) | ||
// } | ||
// | ||
// if membersAdded, err := addMembers(team, input.Members); err != nil { | ||
// return TeamState{ | ||
// Input: input, | ||
// Members: membersAdded, | ||
// }, infer.ResourceInitFailedError{Reasons: []string{ | ||
// fmt.Sprintf("Failed to add members: %s", err), | ||
// }} | ||
// } | ||
// | ||
// return TeamState{input, input.Members}, nil | ||
// } | ||
// | ||
// If the the above example errors with [infer.ResourceInitFailedError], the next Update | ||
// will be called with `state` equal to what was returned alongside | ||
// [infer.ResourceInitFailedError]. | ||
type ResourceInitFailedError struct { | ||
Reasons []string | ||
} | ||
|
||
func (err ResourceInitFailedError) Error() string { return "resource failed to initialize" } | ||
|
||
// An error indicating a bug in the provider implementation. | ||
type ProviderError struct { | ||
Inner error | ||
} | ||
|
||
// Create a new [ProviderErrorf]. | ||
func ProviderErrorf(msg string, a ...any) error { | ||
return ProviderError{fmt.Errorf(msg, a...)} | ||
} | ||
|
||
func (err ProviderError) Error() string { | ||
const ( | ||
prefix = "provider error" | ||
suffix = "; please report this to the provider author" | ||
) | ||
if err.Inner == nil { | ||
return prefix + suffix | ||
} | ||
return prefix + ": " + err.Inner.Error() + suffix | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2024, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package internal | ||
|
||
import "fmt" | ||
|
||
// A error that indicates a bug in the pulumi-go-provider framework. | ||
type InternalError struct { | ||
Inner error | ||
} | ||
|
||
func InternalErrorf(msg string, a ...any) error { | ||
return InternalError{fmt.Errorf(msg, a...)} | ||
} | ||
|
||
func (err InternalError) Error() string { | ||
const ( | ||
prefix = "internal error" | ||
suffix = "; please report this to https://github.com/pulumi/pulumi-go-provider/issues" | ||
) | ||
if err.Inner == nil { | ||
return prefix + suffix | ||
} | ||
return prefix + ": " + err.Inner.Error() + suffix | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters