Skip to content

Commit 150defb

Browse files
committed
Handle generating pipeline failure
1 parent 945bdc4 commit 150defb

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

internal/cmdexport/cmdexport.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ type ExportRunner struct {
8787

8888
// runE generates the pipeline and writes it into a file or stdout.
8989
func (r *ExportRunner) runE(c *cobra.Command, args []string) error {
90-
pipeline := r.Pipeline.Init(r.PipelineConfig).Generate()
90+
pipeline, e := r.Pipeline.Init(r.PipelineConfig).Generate()
91+
92+
if e != nil {
93+
return e
94+
}
9195

9296
if r.OutputFilePath != "" {
9397
fo, err := os.Create(r.OutputFilePath)

internal/cmdexport/orchestrators/cloudbuild.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ func (p *CloudBuild) Init(config *types.PipelineConfig) Pipeline {
5454
return p
5555
}
5656

57-
func (p *CloudBuild) Generate() []byte {
58-
data, _ := yaml.Marshal(p)
59-
60-
return data
57+
func (p *CloudBuild) Generate() (out []byte, err error) {
58+
return yaml.Marshal(p)
6159
}

internal/cmdexport/orchestrators/githubactions.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ func (p *GitHubActions) Init(config *types.PipelineConfig) Pipeline {
8282
return p
8383
}
8484

85-
func (p *GitHubActions) Generate() []byte {
86-
data, _ := yaml.Marshal(p)
87-
88-
return data
85+
func (p *GitHubActions) Generate() (out []byte, err error) {
86+
return yaml.Marshal(p)
8987
}

internal/cmdexport/orchestrators/pipeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ const KptImage = "gongpu/kpt:latest"
2222
// Pipeline is an abstraction of different workflow orchestrators.
2323
type Pipeline interface {
2424
Init(config *types.PipelineConfig) Pipeline
25-
Generate() []byte
25+
Generate() (out []byte, err error)
2626
}

internal/cmdexport/orchestrators/pipeline_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestPipeline(t *testing.T) {
4747
testCase := testCases[i]
4848

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

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

0 commit comments

Comments
 (0)