Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/octopus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"fmt"
"github.com/AlecAivazis/survey/v2/terminal"
version "github.com/OctopusDeploy/cli"
"github.com/OctopusDeploy/cli/pkg/constants"
"github.com/briandowns/spinner"
"github.com/spf13/viper"
"github.com/ztrue/tracerr"
"os"
"strings"
"time"
Expand Down Expand Up @@ -71,7 +73,11 @@ func main() {
cmd.SetErr(terminal.NewAnsiStderr(os.Stderr))

if err := cmd.Execute(); err != nil {
cmd.PrintErr(err)
if cmd.Flag(constants.FlagDebug).Value.String() == fmt.Sprintf("%v", true) {
cmd.PrintErr(tracerr.Sprint(err))
} else {
cmd.PrintErr(err)
}
cmd.Println()

if usageError, ok := err.(*usage.UsageError); ok {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
github.com/ztrue/tracerr v0.3.0
golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15
golang.org/x/term v0.3.0
)
Expand All @@ -37,6 +38,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e h1:9MlwzLdW7QSDrhDjFlsEYmxpFyIoXmYRon3dt0io31k=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down Expand Up @@ -258,6 +260,8 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/ztrue/tracerr v0.3.0 h1:lDi6EgEYhPYPnKcjsYzmWw4EkFEoA/gfe+I9Y5f+h6Y=
github.com/ztrue/tracerr v0.3.0/go.mod h1:qEalzze4VN9O8tnhBXScfCrmoJo10o8TN5ciKjm6Mww=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand Down
21 changes: 11 additions & 10 deletions pkg/apiclient/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package apiclient
import (
"errors"
"fmt"
"github.com/ztrue/tracerr"
"net/url"
"strings"

Expand Down Expand Up @@ -85,7 +86,7 @@ func NewClientFactory(httpClient *http.Client, host string, apiKey string, space

hostUrl, err := url.Parse(host)
if err != nil {
return nil, err
return nil, tracerr.Wrap(err)
}

clientImpl := &Client{
Expand All @@ -108,9 +109,9 @@ func NewClientFactoryFromConfig(ask question.AskProvider) (ClientFactory, error)
apiKey := viper.GetString(constants.ConfigApiKey)
spaceNameOrID := viper.GetString(constants.ConfigSpace)

errs := ValidateMandatoryEnvironment(host, apiKey)
if errs != nil {
return nil, errs
err := ValidateMandatoryEnvironment(host, apiKey)
if err != nil {
return nil, tracerr.Wrap(err)
}

var httpClient *http.Client
Expand Down Expand Up @@ -167,7 +168,7 @@ func (c *Client) GetSpacedClient(requester Requester) (*octopusApiClient.Client,
// We could have been given either a space name, or a space ID, so we need to use the SystemClient to go look it up.
systemClient, err := c.GetSystemClient(requester)
if err != nil {
return nil, err
return nil, tracerr.Wrap(err)
}

// if the caller has not specified a space, prompt interactively
Expand All @@ -180,7 +181,7 @@ func (c *Client) GetSpacedClient(requester Requester) (*octopusApiClient.Client,

allSpaces, err := systemClient.Spaces.GetAll()
if err != nil {
return nil, err
return nil, tracerr.Wrap(err)
}

switch len(allSpaces) {
Expand All @@ -197,7 +198,7 @@ func (c *Client) GetSpacedClient(requester Requester) (*octopusApiClient.Client,
"You have not specified a Space. Please select one:", allSpaces, func(item *spaces.Space) string { return item.GetName() })

if err != nil {
return nil, err
return nil, tracerr.Wrap(err)
}
c.ActiveSpace = selectedSpace
c.SpaceNameOrID = selectedSpace.ID
Expand All @@ -211,7 +212,7 @@ func (c *Client) GetSpacedClient(requester Requester) (*octopusApiClient.Client,
// for that logic so the most pragmatic way to achieve that is to iterate the list of spaces client-side
allSpaces, err := systemClient.Spaces.GetAll()
if err != nil {
return nil, fmt.Errorf("cannot load spaces. Error: %v", err)
return nil, tracerr.Wrap(fmt.Errorf("cannot load spaces. Error: %v", err))
}

var foundSpace *spaces.Space = nil
Expand Down Expand Up @@ -240,7 +241,7 @@ func (c *Client) GetSpacedClient(requester Requester) (*octopusApiClient.Client,

scopedClient, err := octopusApiClient.NewClientForTool(c.HttpClient, c.ApiUrl, c.ApiKey, foundSpaceID, requester.GetRequester())
if err != nil {
return nil, err
return nil, tracerr.Wrap(err)
}
// stash for future use
c.SpaceScopedClient = scopedClient
Expand All @@ -267,7 +268,7 @@ func (c *Client) GetSystemClient(requester Requester) (*octopusApiClient.Client,

systemClient, err := octopusApiClient.NewClientForTool(c.HttpClient, c.ApiUrl, c.ApiKey, "", requester.GetRequester()) // deliberate empty string for space here
if err != nil {
return nil, err
return nil, tracerr.Wrap(err)
}
// stash for future use
c.SystemClient = systemClient
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/account/helper/helper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helper

import (
"github.com/ztrue/tracerr"
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
Expand All @@ -18,11 +19,11 @@ loop:
Name: envName,
})
if err != nil {
return nil, err
return nil, tracerr.Wrap(err)
}
allMatches, err := matches.GetAllPages(octopus.Environments.GetClient())
if err != nil {
return nil, err
return nil, tracerr.Wrap(err)
}
for _, match := range allMatches {
if strings.EqualFold(envName, match.Name) {
Expand Down
11 changes: 6 additions & 5 deletions pkg/cmd/package/nuget/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package create
import (
"errors"
"fmt"
"github.com/ztrue/tracerr"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -245,12 +246,12 @@ func applyDefaultsToUnspecifiedPackageOptions(opts *NuPkgCreateOptions) error {
func getReleaseNotesFromFile(filePath string) (string, error) {
_, err := os.Stat(filePath)
if err != nil {
return "", err
return "", tracerr.Wrap(err)
}

notes, err := os.ReadFile(filePath)
if err != nil {
return "", err
return "", tracerr.Wrap(err)
}

return string(notes), nil
Expand Down Expand Up @@ -282,7 +283,7 @@ func GenerateNuSpec(opts *NuPkgCreateOptions) (string, error) {
notes, err := getReleaseNotesFromFile(opts.ReleaseNotesFile.Value)
releaseNotes = notes
if err != nil {
return "", err
return "", tracerr.Wrap(err)
}
}

Expand All @@ -304,12 +305,12 @@ func GenerateNuSpec(opts *NuPkgCreateOptions) (string, error) {

file, err := os.Create(filePath)
if err != nil {
return "", err
return "", tracerr.Wrap(err)
}

_, err = file.WriteString(sb.String())
if err != nil {
return "", err
return "", tracerr.Wrap(err)
}

return filePath, file.Close()
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/package/support/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/OctopusDeploy/cli/pkg/util/flag"
"github.com/bmatcuk/doublestar/v4"
"github.com/spf13/cobra"
"github.com/ztrue/tracerr"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -261,7 +262,7 @@ func getDistinctPatternMatches(basePath string, patterns []string) ([]string, er
for _, pattern := range patterns {
paths, err := doublestar.Glob(fileSys, filepath.ToSlash(pattern))
if err != nil {
return nil, err
return nil, tracerr.Wrap(err)
}
filePaths = append(filePaths, paths...)
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/cmd/package/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"github.com/OctopusDeploy/cli/pkg/apiclient"
"github.com/ztrue/tracerr"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -160,7 +161,7 @@ func uploadRun(cmd *cobra.Command, f factory.Factory, flags *UploadFlags) error
}

if !continueOnError {
return err
return tracerr.Wrap(err)
} // else keep going to the next file.

// side-effect: If there is a single failed upload, and you specify --continue-on-error, then
Expand Down Expand Up @@ -192,15 +193,15 @@ func uploadRun(cmd *cobra.Command, f factory.Factory, flags *UploadFlags) error
if err == nil && globMatches == nil {
err = doUpload(pkgString)
if err != nil {
return err
return tracerr.Wrap(err)
}
} else if err != nil { // invalid glob pattern
return err
return tracerr.Wrap(err)
} else { // glob matched at least 1 thing
for _, globMatch := range globMatches {
err = doUpload(globMatch)
if err != nil {
return err
return tracerr.Wrap(err)
}
}
}
Expand Down Expand Up @@ -229,12 +230,12 @@ func uploadFileAtPath(octopus newclient.Client, space *spaces.Space, path string

fileReader, err := opener(path)
if err != nil {
return false, err
return false, tracerr.Wrap(err)
}

// Note: the PackageUploadResponse has a lot of information in it, but we've chosen not to do anything
// with it in the CLI at this time.
_, created, err := packages.Upload(octopus, space.ID, filepath.Base(path), fileReader, overwriteMode)
_ = fileReader.Close()
return created, err
return created, tracerr.Wrap(err)
}
Loading