Skip to content

Commit

Permalink
send errors to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksym Trofimenko committed Dec 8, 2024
1 parent 5fcbb62 commit f5a0bfd
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ var buildCmd = &cobra.Command{

info, err := build.GetReadme(cwd)
if err != nil {
fmt.Printf("unable to get README.md by path %s: %v\n", cwd, err)
fmt.Fprintf(os.Stderr, "unable to get README.md by path %s: %v\n", cwd, err)
return
}

platformClient, err := api.NewClientWithResponses(platformApiURL)
if err != nil {
fmt.Printf("unable to create API client: %v\n", err)
fmt.Fprintf(os.Stderr, "unable to create API client: %v\n", err)
return
}

Expand All @@ -51,12 +51,12 @@ var buildCmd = &cobra.Command{
}

if len(componentsApi) == 0 {
fmt.Printf("component registry is empty\n")
fmt.Fprintf(os.Stderr, "component registry is empty\n")
return
}

if !semver.IsValid(version) {
fmt.Printf("version is invalid semver v2 version\n")
fmt.Fprintf(os.Stderr, "version is invalid semver v2 version\n")
return
}

Expand All @@ -72,17 +72,17 @@ var buildCmd = &cobra.Command{
})

if err != nil {
fmt.Printf("unable to publish module: %v\n", err)
fmt.Fprintf(os.Stderr, "unable to publish module: %v\n", err)
return
}
if resp.JSON200 == nil {
fmt.Printf("unknown server error: %s\n", string(resp.Body))
fmt.Fprintf(os.Stderr, "unknown server error: %s\n", string(resp.Body))
return
}

publishResponse := resp.JSON200
if publishResponse.Module == nil || publishResponse.Options == nil {
fmt.Printf("invalid server response\n")
fmt.Fprintf(os.Stderr, "invalid server response\n")
return
}

Expand All @@ -96,7 +96,7 @@ var buildCmd = &cobra.Command{

// @todo build failure ignored
if err := build.Build(ctx, cwd, pathToMain, buildOpts); err != nil {
fmt.Printf("unable to build: %v\n", err)
fmt.Fprintf(os.Stderr, "unable to build: %v\n", err)
return
}
image := fmt.Sprintf("%s:%s", publishResponse.Options.Repo, publishResponse.Options.Tag)
Expand All @@ -108,7 +108,7 @@ var buildCmd = &cobra.Command{
Username: publishResponse.Options.Username,
Password: publishResponse.Options.Password,
}); err != nil {
fmt.Printf("unable to push: image %s; error: %v\n", image, err)
fmt.Fprintf(os.Stderr, "unable to push: image %s; error: %v\n", image, err)
return
}
_, err = platformClient.UpdateModuleVersion(ctx, api.UpdateModuleVersionRequest{
Expand All @@ -120,9 +120,10 @@ var buildCmd = &cobra.Command{
return nil
})
if err != nil {
fmt.Printf("unable to update version with image %s; error: %v\n", image, err)
fmt.Fprintf(os.Stderr, "unable to update version with image %s; error: %v\n", image, err)
return
}

fmt.Printf("image %s succesfully pushed\n", image)
},
}
Expand Down

0 comments on commit f5a0bfd

Please sign in to comment.