[cli/import] - Handle panic during import codegen (#7265)
This commit is contained in:
parent
4e9e017cd2
commit
470be8c2b8
|
@ -8,6 +8,9 @@
|
|||
|
||||
- [codegen] - Include properties with an underlying type of string on Go provider instances.
|
||||
|
||||
- [cli] - Provide a more helpful error instead of panicking when codegen fails during import.
|
||||
[#7265](https://github.com/pulumi/pulumi/pull/7265)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- [sdk/python] - Fix regression in behaviour for `Output.from_input({})`
|
||||
|
|
|
@ -198,6 +198,20 @@ func generateImportedDefinitions(out io.Writer, stackName tokens.QName, projectN
|
|||
snap *deploy.Snapshot, programGenerator programGeneratorFunc, names importer.NameTable,
|
||||
imports []deploy.Import, protectResources bool) (bool, error) {
|
||||
|
||||
defer func() {
|
||||
v := recover()
|
||||
if v != nil {
|
||||
errMsg := strings.Builder{}
|
||||
errMsg.WriteString("Your resource has been imported into Pulumi state, but there was an error generating the import code.\n") //nolint:lll
|
||||
errMsg.WriteString("\n")
|
||||
if strings.Contains(fmt.Sprintf("%v", v), "invalid Go source code:") {
|
||||
errMsg.WriteString("You will need to copy and paste the generated code into your Pulumi application and manually edit it to correct any errors.\n\n") //nolint:lll
|
||||
}
|
||||
errMsg.WriteString(fmt.Sprintf("%v\n", v))
|
||||
fmt.Print(errMsg.String())
|
||||
}
|
||||
}()
|
||||
|
||||
resourceTable := map[resource.URN]*resource.State{}
|
||||
for _, r := range snap.Resources {
|
||||
if !r.Delete {
|
||||
|
@ -499,7 +513,7 @@ func newImportCmd() *cobra.Command {
|
|||
return result.FromError(err)
|
||||
}
|
||||
if protectResources {
|
||||
_, err := helperWriter.Write([]byte("Please note, that the imported resources are marked as protected. " +
|
||||
_, err := helperWriter.Write([]byte("Please note that the imported resources are marked as protected. " +
|
||||
"To destroy them\n" +
|
||||
"you will need to remove the `protect` option and run `pulumi update` *before*\n" +
|
||||
"the destroy will take effect.\n\n"))
|
||||
|
|
Loading…
Reference in a new issue