Skip to content

Commit

Permalink
Handle generating pipeline failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuGongpu committed Jul 1, 2020
1 parent 945bdc4 commit 150defb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 5 additions & 1 deletion internal/cmdexport/cmdexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ type ExportRunner struct {

// runE generates the pipeline and writes it into a file or stdout.
func (r *ExportRunner) runE(c *cobra.Command, args []string) error {
pipeline := r.Pipeline.Init(r.PipelineConfig).Generate()
pipeline, e := r.Pipeline.Init(r.PipelineConfig).Generate()

if e != nil {
return e
}

if r.OutputFilePath != "" {
fo, err := os.Create(r.OutputFilePath)
Expand Down
6 changes: 2 additions & 4 deletions internal/cmdexport/orchestrators/cloudbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ func (p *CloudBuild) Init(config *types.PipelineConfig) Pipeline {
return p
}

func (p *CloudBuild) Generate() []byte {
data, _ := yaml.Marshal(p)

return data
func (p *CloudBuild) Generate() (out []byte, err error) {
return yaml.Marshal(p)
}
6 changes: 2 additions & 4 deletions internal/cmdexport/orchestrators/githubactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ func (p *GitHubActions) Init(config *types.PipelineConfig) Pipeline {
return p
}

func (p *GitHubActions) Generate() []byte {
data, _ := yaml.Marshal(p)

return data
func (p *GitHubActions) Generate() (out []byte, err error) {
return yaml.Marshal(p)
}
2 changes: 1 addition & 1 deletion internal/cmdexport/orchestrators/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ const KptImage = "gongpu/kpt:latest"
// Pipeline is an abstraction of different workflow orchestrators.
type Pipeline interface {
Init(config *types.PipelineConfig) Pipeline
Generate() []byte
Generate() (out []byte, err error)
}
2 changes: 1 addition & 1 deletion internal/cmdexport/orchestrators/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestPipeline(t *testing.T) {
testCase := testCases[i]

t.Run(testCase.description, func(t *testing.T) {
pipeline := pipeline.Init(testCase.config).Generate()
pipeline, _ := pipeline.Init(testCase.config).Generate()

actual := string(pipeline)
expected := strings.TrimLeft(testCase.expected, "\n")
Expand Down

0 comments on commit 150defb

Please sign in to comment.