pulumi/sdk/go/x/auto/errors.go

118 lines
2.5 KiB
Go
Raw Normal View History

2020-07-18 05:04:37 +02:00
package auto
import (
2020-07-22 03:44:53 +02:00
"fmt"
2020-07-18 05:04:37 +02:00
"strings"
"github.com/pkg/errors"
)
type autoError struct {
stdout string
stderr string
code int
err error
}
func newAutoError(err error, stdout, stderr string, code int) autoError {
return autoError{
stdout,
stderr,
code,
err,
}
}
func (ae autoError) Error() string {
2020-07-22 03:44:53 +02:00
return errors.Wrap(
ae.err, fmt.Sprintf("code: %d\n, stdout: %s\n, stderr: %s\n", ae.code, ae.stdout, ae.stderr),
).Error()
2020-07-18 05:04:37 +02:00
}
2020-07-22 01:21:47 +02:00
func IsConcurrentUpdateError(e error) bool {
2020-07-18 05:04:37 +02:00
ae, ok := e.(autoError)
if !ok {
return false
}
return strings.Contains(ae.stderr, "[409] Conflict: Another update is currently in progress.")
}
2020-07-22 01:21:47 +02:00
2020-07-22 03:17:38 +02:00
// IsCompilationError returns true if there was an error compiling the user program (only typescript, go, dotnet)
2020-07-22 01:21:47 +02:00
func IsCompilationError(e error) bool {
as, ok := e.(autoError)
if !ok {
return false
}
// dotnet
if strings.Contains(as.stdout, "Build FAILED.") {
return true
}
// go
2020-07-22 03:17:38 +02:00
// TODO: flimsy for go
2020-07-22 01:21:47 +02:00
if strings.Contains(as.stdout, ": syntax error:") {
return true
}
if strings.Contains(as.stdout, ": undefined:") {
return true
}
// typescript
if strings.Contains(as.stdout, "Unable to compile TypeScript") {
return true
}
return false
}
2020-07-22 03:17:38 +02:00
// IsRuntimeError returns true if there was an error in the user program at during execution.
func IsRuntimeError(e error) bool {
as, ok := e.(autoError)
if !ok {
return false
}
if IsCompilationError(e) {
return false
}
// js/ts/dotnet/python
if strings.Contains(as.stdout, "failed with an unhandled exception:") {
return true
}
// go
if strings.Contains(as.stdout, "panic: runtime error:") {
return true
}
if strings.Contains(as.stdout, "an unhandled error occurred:") {
return true
}
if strings.Contains(as.Error(), "go inline source runtime error") {
return true
}
2020-07-22 03:17:38 +02:00
return false
}
2020-07-22 03:27:31 +02:00
2020-07-22 03:39:35 +02:00
// IsUnexpectedEngineError returns true if the pulumi core engine encountered an error (most likely a bug).
func IsUnexpectedEngineError(e error) bool {
// TODO: figure out how to write a test for this
as, ok := e.(autoError)
if !ok {
return false
}
return strings.Contains(as.stdout, "The Pulumi CLI encountered a fatal error. This is a bug!")
}
2020-07-22 03:27:31 +02:00
// TODO IsProviderError
// errors are not consistently labeled, will likely need a new strategy.
// Error creating S3 bucket: BucketAlreadyExists: The requested bucket name is not available.
// could not make instance of 'aws:s3/bucket:Bucket': name '...' plus 7 random chars is longer than maximum length 63
// Error creating S3 bucket: IllegalLocationConstraintException