Skip to content

Commit

Permalink
Merge pull request #4364 from tejal29/add_suggestion_protos
Browse files Browse the repository at this point in the history
add suggestion protos and hook up with Event API
  • Loading branch information
nkubala authored Jun 23, 2020
2 parents 22135d7 + 5e1869d commit 93169dd
Show file tree
Hide file tree
Showing 6 changed files with 822 additions and 309 deletions.
332 changes: 319 additions & 13 deletions docs/content/en/api/skaffold.swagger.json

Large diffs are not rendered by default.

85 changes: 59 additions & 26 deletions docs/content/en/docs/references/api/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ Describes all the methods for the Skaffold API



<a name="proto.ActionableErr"></a>
#### ActionableErr
`ActionableErr` defines an error that occurred along with an optional list of suggestions


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| errCode | [StatusCode](#proto.StatusCode) | | error code representing the error |
| message | [string](#string) | | message describing the error. |
| suggestions | [Suggestion](#proto.Suggestion) | repeated | list of suggestions |







<a name="proto.BuildEvent"></a>
#### BuildEvent
`BuildEvent` describes the build status per artifact, and will be emitted by Skaffold anytime a build starts or finishes, successfully or not.
Expand All @@ -62,8 +79,9 @@ If the build fails, an error will be attached to the event.
| ----- | ---- | ----- | ----------- |
| artifact | [string](#string) | | artifact name |
| status | [string](#string) | | artifact build status oneof: InProgress, Completed, Failed |
| err | [string](#string) | | error when build status is Failed. |
| errCode | [StatusCode](#proto.StatusCode) | | status code representing success or failure |
| err | [string](#string) | | Deprecated. Use actionableErr.message. error when build status is Failed. |
| errCode | [StatusCode](#proto.StatusCode) | | Deprecated. Use actionableErr.errCode. status code representing success or failure |
| actionableErr | [ActionableErr](#proto.ActionableErr) | | actionable error message |



Expand Down Expand Up @@ -200,8 +218,9 @@ anytime a deployment starts or completes, successfully or not.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| status | [string](#string) | | deployment status oneof: InProgress, Completed, Failed |
| err | [string](#string) | | error when status is Failed |
| errCode | [StatusCode](#proto.StatusCode) | | status code representing success or failure |
| err | [string](#string) | | Deprecated. Use actionableErr.message. error when status is Failed |
| errCode | [StatusCode](#proto.StatusCode) | | Deprecated. Use actionableErr.errCode. status code representing success or failure |
| actionableErr | [ActionableErr](#proto.ActionableErr) | | actionable error message |



Expand Down Expand Up @@ -266,23 +285,7 @@ anytime a deployment starts or completes, successfully or not.
| ----- | ---- | ----- | ----------- |
| iteration | [int32](#int32) | | dev loop iteration. 0 represents initialization loop. |
| status | [string](#string) | | dev loop status oneof: In Progress, Completed, Failed |
| err | [ErrDef](#proto.ErrDef) | | actionable error message |







<a name="proto.ErrDef"></a>
#### ErrDef
`ErrDef` defines an error occurred along with an optional suggestions


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| errCode | [StatusCode](#proto.StatusCode) | | error code representing the error |
| message | [string](#string) | | message describing the error. |
| err | [ActionableErr](#proto.ActionableErr) | | actionable error message |



Expand Down Expand Up @@ -324,8 +327,9 @@ FileSyncEvent describes the sync status.
| fileCount | [int32](#int32) | | number of files synced |
| image | [string](#string) | | the container image to which files are sycned. |
| status | [string](#string) | | status of file sync. one of: Not Started, In progress, Succeeded, Failed. |
| err | [string](#string) | | error in case of status failed. |
| errCode | [StatusCode](#proto.StatusCode) | | status code representing success or failure |
| err | [string](#string) | | Deprecated. Use actionableErr.message. error in case of status failed. |
| errCode | [StatusCode](#proto.StatusCode) | | Deprecated. Use actionableErr.errCode. status code representing success or failure |
| actionableErr | [ActionableErr](#proto.ActionableErr) | | actionable error message |



Expand Down Expand Up @@ -484,8 +488,9 @@ will be sent with the new status.
| resource | [string](#string) | | |
| status | [string](#string) | | |
| message | [string](#string) | | |
| err | [string](#string) | | |
| err | [string](#string) | | Deprecated. Use actionableErr.message. |
| statusCode | [StatusCode](#proto.StatusCode) | | |
| actionableErr | [ActionableErr](#proto.ActionableErr) | | actionable error message |



Expand Down Expand Up @@ -569,8 +574,9 @@ will be sent with the new status.
| ----- | ---- | ----- | ----------- |
| status | [string](#string) | | |
| message | [string](#string) | | |
| err | [string](#string) | | |
| errCode | [StatusCode](#proto.StatusCode) | | status code representing success or failure |
| err | [string](#string) | | Deprecated. Use actionableErr.message. |
| errCode | [StatusCode](#proto.StatusCode) | | Deprecated. Use actionableErr.errCode. status code representing success or failure |
| actionableErr | [ActionableErr](#proto.ActionableErr) | | actionable error message |



Expand Down Expand Up @@ -610,6 +616,22 @@ will be sent with the new status.



<a name="proto.Suggestion"></a>
#### Suggestion
Suggestion defines the action a user needs to recover from an error.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| suggestionCode | [SuggestionCode](#proto.SuggestionCode) | | code representing a suggestion |
| action | [string](#string) | | action represents the suggestion action |







<a name="proto.TriggerRequest"></a>
#### TriggerRequest

Expand Down Expand Up @@ -763,6 +785,17 @@ BUILD, DEPLOY, STATUSCHECK, DEVINIT
| DEVINIT_REGISTER_CONFIG_DEP | 704 | Failed to configure watcher for Skaffold configuration file. |



<a name="proto.SuggestionCode"></a>

### SuggestionCode
Enum for Suggestion codes

| Name | Number | Description |
| ---- | ------ | ----------- |
| NIL | 0 | default nil suggestion. This is usually set when no error happens. |


<!-- end enums -->

<!-- end HasExtensions -->
Expand Down
35 changes: 23 additions & 12 deletions pkg/skaffold/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,29 @@ var (

type Phase string

func ErrorCodeFromError(phase Phase, _ error) proto.StatusCode {
// ActionableErr returns an actionable error message with suggestions
func ActionableErr(phase Phase, err error) *proto.ActionableErr {
aiErr := proto.ActionableErr{
ErrCode: defaultErrorCodeFromError(phase),
Message: err.Error(),
Suggestions: nil,
}

return &aiErr
}

func ShowAIError(err error, opts config.SkaffoldOptions) error {
for _, v := range knownBuildProblems {
if v.regexp.MatchString(err.Error()) {
if s := v.suggestion(opts); s != "" {
return fmt.Errorf("%s. %s", v.description, s)
}
}
}
return ErrNoSuggestionFound
}

func defaultErrorCodeFromError(phase Phase) proto.StatusCode {
switch phase {
case Build:
return proto.StatusCode_BUILD_UNKNOWN
Expand All @@ -57,14 +79,3 @@ func ErrorCodeFromError(phase Phase, _ error) proto.StatusCode {
}
return proto.StatusCode_UNKNOWN_ERROR
}

func ShowAIError(err error, opts config.SkaffoldOptions) error {
for _, v := range knownBuildProblems {
if v.regexp.MatchString(err.Error()) {
if s := v.suggestion(opts); s != "" {
return fmt.Errorf("%s. %s", v.description, s)
}
}
}
return ErrNoSuggestionFound
}
51 changes: 32 additions & 19 deletions pkg/skaffold/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,11 @@ func DeployInProgress() {

// DeployFailed notifies that non-fatal errors were encountered during a deployment.
func DeployFailed(err error) {
statusCode := sErrors.ErrorCodeFromError(sErrors.Deploy, err)
handler.handleDeployEvent(&proto.DeployEvent{Status: Failed, Err: err.Error(), ErrCode: statusCode})
aiErr := sErrors.ActionableErr(sErrors.Deploy, err)
handler.handleDeployEvent(&proto.DeployEvent{Status: Failed,
Err: err.Error(),
ErrCode: aiErr.ErrCode,
ActionableErr: aiErr})
}

// DeployEvent notifies that a deployment of non fatal interesting errors during deploy.
Expand All @@ -193,12 +196,12 @@ func statusCheckEventSucceeded() {
}

func statusCheckEventFailed(err error) {
statusCode := sErrors.ErrorCodeFromError(sErrors.StatusCheck, err)
aiErr := sErrors.ActionableErr(sErrors.StatusCheck, err)
handler.handleStatusCheckEvent(&proto.StatusCheckEvent{
Status: Failed,
Err: err.Error(),
ErrCode: statusCode,
})
Status: Failed,
Err: err.Error(),
ErrCode: aiErr.ErrCode,
ActionableErr: aiErr})
}

func StatusCheckEventStarted() {
Expand Down Expand Up @@ -237,7 +240,10 @@ func resourceStatusCheckEventFailed(r string, statusCode proto.StatusCode, err e
Status: Failed,
Err: err.Error(),
StatusCode: statusCode,
})
ActionableErr: &proto.ActionableErr{
ErrCode: statusCode,
Message: err.Error(),
}})
}

func ResourceStatusCheckEventUpdated(r string, statusCode proto.StatusCode, status string) {
Expand All @@ -261,8 +267,13 @@ func BuildInProgress(imageName string) {

// BuildFailed notifies that a build has failed.
func BuildFailed(imageName string, err error) {
statusCode := sErrors.ErrorCodeFromError(sErrors.Build, err)
handler.handleBuildEvent(&proto.BuildEvent{Artifact: imageName, Status: Failed, Err: err.Error(), ErrCode: statusCode})
aiErr := sErrors.ActionableErr(sErrors.Build, err)
handler.handleBuildEvent(&proto.BuildEvent{
Artifact: imageName,
Status: Failed,
Err: err.Error(),
ErrCode: aiErr.ErrCode,
ActionableErr: aiErr})
}

// BuildComplete notifies that a build has completed.
Expand All @@ -276,20 +287,21 @@ func DevLoopInProgress(i int) {
}

// DevLoopFailed notifies that a dev loop has failed with an error code
func DevLoopFailedWithErrorCode(i int, errCode proto.StatusCode, err error) {
func DevLoopFailedWithErrorCode(i int, statusCode proto.StatusCode, err error) {
ai := &proto.ActionableErr{
ErrCode: statusCode,
Message: err.Error(),
}
handler.handleDevLoopEvent(&proto.DevLoopEvent{
Iteration: int32(i),
Status: Failed,
Err: &proto.ErrDef{
ErrCode: errCode,
Message: err.Error(),
}})
Err: ai})
}

// DevLoopFailed notifies that a dev loop has failed in a given phase
func DevLoopFailedInPhase(iteration int, phase sErrors.Phase, err error) {
statusCode := sErrors.ErrorCodeFromError(phase, err)
DevLoopFailedWithErrorCode(iteration, statusCode, err)
ai := sErrors.ActionableErr(phase, err)
DevLoopFailedWithErrorCode(iteration, ai.ErrCode, err)
}

// DevLoopComplete notifies that a dev loop has completed.
Expand All @@ -304,8 +316,9 @@ func FileSyncInProgress(fileCount int, image string) {

// FileSyncFailed notifies that a file sync has failed.
func FileSyncFailed(fileCount int, image string, err error) {
statusCode := sErrors.ErrorCodeFromError(sErrors.FileSync, err)
handler.handleFileSyncEvent(&proto.FileSyncEvent{FileCount: int32(fileCount), Image: image, Status: Failed, Err: err.Error(), ErrCode: statusCode})
aiErr := sErrors.ActionableErr(sErrors.FileSync, err)
handler.handleFileSyncEvent(&proto.FileSyncEvent{FileCount: int32(fileCount), Image: image, Status: Failed,
Err: err.Error(), ErrCode: aiErr.ErrCode, ActionableErr: aiErr})
}

// FileSyncSucceeded notifies that a file sync has succeeded.
Expand Down
Loading

0 comments on commit 93169dd

Please sign in to comment.