addrs: Resource.String shouldn't ever crash
Previously we had a panic in here for invalid resource modes. While that does always indicate a programming error, it's frustrating to have a crasher inside a String method since it often impedes our ability to report an error properly, since the error reporting itself can crash. Instead we'll just return an invalid string and hope the caller really is bailing out with an error message.
This commit is contained in:
parent
c4fac74371
commit
5e8445b7a5
|
@ -22,7 +22,9 @@ func (r Resource) String() string {
|
||||||
case DataResourceMode:
|
case DataResourceMode:
|
||||||
return fmt.Sprintf("data.%s.%s", r.Type, r.Name)
|
return fmt.Sprintf("data.%s.%s", r.Type, r.Name)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("resource address with invalid mode %s", r.Mode))
|
// Should never happen, but we'll return a string here rather than
|
||||||
|
// crashing just in case it does.
|
||||||
|
return fmt.Sprintf("<invalid>.%s.%s", r.Type, r.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue