github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/jib/errors.go (about)

     1  /*
     2  Copyright 2019 The Skaffold Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package jib
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  
    23  	sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
    24  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log"
    25  	"github.com/GoogleContainerTools/skaffold/proto/v1"
    26  )
    27  
    28  func unknownPluginType(ws string) error {
    29  	return sErrors.NewErrorWithStatusCode(
    30  		&proto.ActionableErr{
    31  			Message: fmt.Sprintf("Unknown Jib builder type for workspace %s", ws),
    32  			ErrCode: proto.StatusCode_BUILD_UNKNOWN_JIB_PLUGIN_TYPE,
    33  			Suggestions: []*proto.Suggestion{
    34  				{
    35  					SuggestionCode: proto.SuggestionCode_FIX_JIB_PLUGIN_CONFIGURATION,
    36  					Action:         fmt.Sprintf("Use one of supported Jib plugin types [%s, %s]", JibMaven, JibGradle),
    37  				},
    38  			},
    39  		})
    40  }
    41  
    42  func unableToDeterminePluginType(ws string, err error) error {
    43  	return sErrors.NewError(err,
    44  		&proto.ActionableErr{
    45  			Message: fmt.Sprintf("unable to determine Jib builder type for workspace %s due to %s", ws, err),
    46  			ErrCode: proto.StatusCode_BUILD_UNKNOWN_JIB_PLUGIN_TYPE,
    47  			Suggestions: []*proto.Suggestion{
    48  				{
    49  					SuggestionCode: proto.SuggestionCode_FIX_JIB_PLUGIN_CONFIGURATION,
    50  					Action:         fmt.Sprintf("Use one of supported Jib plugin types [%s, %s]", JibMaven, JibGradle),
    51  				},
    52  			},
    53  		})
    54  }
    55  
    56  func dependencyErr(pType PluginType, workspace string, err error) error {
    57  	var code proto.StatusCode
    58  	switch pType {
    59  	case JibMaven:
    60  		code = proto.StatusCode_BUILD_JIB_MAVEN_DEP_ERR
    61  	case JibGradle:
    62  		code = proto.StatusCode_BUILD_JIB_GRADLE_DEP_ERR
    63  	default:
    64  		log.Entry(context.TODO()).Fatal("Unknown jib build type", pType)
    65  	}
    66  	return sErrors.NewError(err,
    67  		&proto.ActionableErr{
    68  			Message: fmt.Sprintf("could not fetch dependencies for workspace %s: %s", workspace, err.Error()),
    69  			ErrCode: code,
    70  		})
    71  }
    72  
    73  func jibToolErr(err error) error {
    74  	return sErrors.NewError(err,
    75  		&proto.ActionableErr{
    76  			Message: err.Error(),
    77  			ErrCode: proto.StatusCode_BUILD_USER_ERROR,
    78  			Suggestions: []*proto.Suggestion{
    79  				{
    80  					SuggestionCode: proto.SuggestionCode_FIX_USER_BUILD_ERR,
    81  					Action:         "See the build transcript for suggestions.",
    82  				},
    83  			},
    84  		})
    85  }