Skip to content

Commit

Permalink
clarify grpc errors for missing source collection
Browse files Browse the repository at this point in the history
  • Loading branch information
samirketema committed Aug 8, 2023
1 parent a666404 commit 6c25324
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/meroxa/turbine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const (
IncompatibleTurbineVersion = `your Turbine library version is incompatible with the Meroxa CLI.
For guidance on updating to the latest version, visit:
https://docs.meroxa.com/beta-overview#updated-meroxa-cli-and-outdated-turbine-library`

grpcFuncCollectionErr = "invalid ProcessCollectionRequest.Collection: embedded message failed validation | " +
"caused by: invalid Collection.Name: value length must be at least 1 runes"
grpcDestCollectionErr = "invalid WriteCollectionRequest.SourceCollection: embedded message failed validation | " +
"caused by: invalid Collection.Name: value length must be at least 1 runes"
missingSourceCollectionErr = `missing source collection, please ensure that you have configured your source correctly:
https://docs.meroxa.com/turbine/troubleshooting"`
)

type AppConfig struct {
Expand Down Expand Up @@ -214,6 +221,11 @@ func RunCmdWithErrorDetection(_ context.Context, cmd *exec.Cmd, _ log.Logger) (s
if stdOutMsg != "" {
errLog = stdOutMsg + errLog
}

if strings.Contains(errLog, "rpc error") {
errLog = clarifyGrpcErrors(errLog)
}

return "", errors.New(errLog)
}
}
Expand Down Expand Up @@ -241,6 +253,20 @@ func trimNonNpmErrorLines(output string) string {
return strings.Join(errorLines, "\n")
}

// TODO: remove this and refactor error handling from turbine-core grpc requests
// This is needed temporarily to provide a more actionable error when the app has no sources defined.
// Longer-term, we need to have more specific, actionable errors rather than grpc validation
// errors surfaced to CLI output.
func clarifyGrpcErrors(errLog string) string {
switch {
case strings.Contains(errLog, grpcFuncCollectionErr):
return missingSourceCollectionErr
case strings.Contains(errLog, grpcDestCollectionErr):
return missingSourceCollectionErr
}
return errLog
}

// SwitchToAppDirectory switches temporarily to the application's directory.
func SwitchToAppDirectory(appPath string) (string, error) {
pwd, err := os.Getwd()
Expand Down

0 comments on commit 6c25324

Please sign in to comment.