Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
12 changes: 7 additions & 5 deletions pkg/commands/aclentry/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/errors"
fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
Expand Down Expand Up @@ -122,18 +122,20 @@ func (c *UpdateCommand) constructBatchInput(serviceID string) (*fastly.BatchModi
err := json.Unmarshal(bs, &input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"File": s,
fsterr.AllowInstrumentation: true,
"File": s,
})
return nil, err
}

if len(input.Entries) == 0 {
err := errors.RemediationError{
err := fsterr.RemediationError{
Inner: fmt.Errorf("missing 'entries' %s", c.file.Value),
Remediation: "Consult the API documentation for the JSON format: https://developer.fastly.com/reference/api/acls/acl-entry/#bulk-update-acl-entries",
}
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"File": string(bs),
fsterr.AllowInstrumentation: true,
"File": string(bs),
})
return nil, err
}
Expand All @@ -146,7 +148,7 @@ func (c *UpdateCommand) constructInput(serviceID string) (*fastly.UpdateACLEntry
var input fastly.UpdateACLEntryInput

if !c.id.WasSet {
return nil, errors.ErrNoID
return nil, fsterr.ErrNoID
}

input.ACLID = c.aclID
Expand Down
16 changes: 10 additions & 6 deletions pkg/commands/compute/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {

if err := language.Build(); err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Language": language.Name,
fsterr.AllowInstrumentation: true,
"Language": language.Name,
})
return err
}
Expand Down Expand Up @@ -202,8 +203,9 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {
err = CreatePackageArchive(files, dest)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Files": files,
"Destination": dest,
fsterr.AllowInstrumentation: true,
"Files": files,
"Destination": dest,
})

spinner.StopFailMessage(msg)
Expand Down Expand Up @@ -247,7 +249,8 @@ func (c *BuildCommand) includeSourceCode(files []string, srcDir string) ([]strin
binFiles, err := GetNonIgnoredFiles("bin", ignoreFiles)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Ignore files": ignoreFiles,
fsterr.AllowInstrumentation: true,
"Ignore files": ignoreFiles,
})
return empty, err
}
Expand All @@ -256,8 +259,9 @@ func (c *BuildCommand) includeSourceCode(files []string, srcDir string) ([]strin
srcFiles, err := GetNonIgnoredFiles(srcDir, ignoreFiles)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Source directory": srcDir,
"Ignore files": ignoreFiles,
fsterr.AllowInstrumentation: true,
"Source directory": srcDir,
"Ignore files": ignoreFiles,
})
return empty, err
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/commands/compute/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,17 @@ func validatePackage(
pkgPath, err = packagePath(packageFlag, projectName, source)
if err != nil {
errLog.AddWithContext(err, map[string]any{
"Package path": packageFlag,
fsterr.AllowInstrumentation: true,
"Package path": packageFlag,
})
return pkgPath, hashSum, err
}

pkgSize, err := packageSize(pkgPath)
if err != nil {
errLog.AddWithContext(err, map[string]any{
"Package path": pkgPath,
fsterr.AllowInstrumentation: true,
"Package path": pkgPath,
})
return pkgPath, hashSum, fsterr.RemediationError{
Inner: fmt.Errorf("error reading package size: %w", err),
Expand Down Expand Up @@ -317,8 +319,9 @@ func validatePackage(
return nil
}); err != nil {
errLog.AddWithContext(err, map[string]any{
"Package path": pkgPath,
"Package size": pkgSize,
fsterr.AllowInstrumentation: true,
"Package path": pkgPath,
"Package size": pkgSize,
})
return pkgPath, hashSum, err
}
Expand Down Expand Up @@ -553,7 +556,8 @@ func manageNoServiceIDFlow(
// have succeeded and so there will be no error.
if err != nil && packageFlag == "" {
errLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
fsterr.AllowInstrumentation: true,
"Service ID": serviceID,
})
return serviceID, serviceVersion, err
}
Expand Down
33 changes: 19 additions & 14 deletions pkg/commands/compute/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
dst, err := verifyDestination(c.dir, spinner, out)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Directory": c.dir,
fsterr.AllowInstrumentation: true,
"Directory": c.dir,
})
return err
}
Expand All @@ -140,8 +141,9 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
name, desc, authors, err := promptOrReturn(c.Globals.Flags, c.manifest, c.dir, email, in, out)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Description": desc,
"Directory": c.dir,
fsterr.AllowInstrumentation: true,
"Description": desc,
"Directory": c.dir,
})
return err
}
Expand Down Expand Up @@ -176,10 +178,11 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
from, branch, tag, err = promptForStarterKit(c.Globals.Flags, language.StarterKits, in, out)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"From": c.cloneFrom,
"Branch": c.branch,
"Tag": c.tag,
"Manifest Exist": false,
fsterr.AllowInstrumentation: true,
"From": c.cloneFrom,
"Branch": c.branch,
"Tag": c.tag,
"Manifest Exist": false,
})
return err
}
Expand All @@ -199,10 +202,11 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
err = fetchPackageTemplate(c, branch, tag, file.Archives, spinner, out)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"From": from,
"Branch": branch,
"Tag": tag,
"Directory": c.dir,
fsterr.AllowInstrumentation: true,
"From": from,
"Branch": branch,
"Tag": tag,
"Directory": c.dir,
})
return err
}
Expand All @@ -211,9 +215,10 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
mf, err = updateManifest(mf, spinner, c.dir, name, desc, authors, language)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Directory": c.dir,
"Description": desc,
"Language": language,
fsterr.AllowInstrumentation: true,
"Directory": c.dir,
"Description": desc,
"Language": language,
})
return err
}
Expand Down
16 changes: 11 additions & 5 deletions pkg/commands/compute/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (c *PackCommand) Exec(_ io.Reader, out io.Writer) (err error) {
err = filesystem.MakeDirectoryIfNotExists(bindir)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
fsterr.AllowInstrumentation: true,
"Wasm directory (relative)": bindir,
})
return err
Expand All @@ -66,13 +67,15 @@ func (c *PackCommand) Exec(_ io.Reader, out io.Writer) (err error) {
src, err := filepath.Abs(c.wasmBinary)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Path (absolute)": src,
fsterr.AllowInstrumentation: true,
"Path (absolute)": src,
})
return err
}
dst, err := filepath.Abs(bin)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
fsterr.AllowInstrumentation: true,
"Wasm destination (relative)": bin,
})
return err
Expand All @@ -87,6 +90,7 @@ func (c *PackCommand) Exec(_ io.Reader, out io.Writer) (err error) {

if err := filesystem.CopyFile(src, dst); err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
fsterr.AllowInstrumentation: true,
"Path (absolute)": src,
"Wasm destination (absolute)": dst,
})
Expand Down Expand Up @@ -130,8 +134,9 @@ func (c *PackCommand) Exec(_ io.Reader, out io.Writer) (err error) {
dst = fmt.Sprintf("pkg/package/%s", manifest.Filename)
if err := filesystem.CopyFile(src, dst); err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Manifest (destination)": dst,
"Manifest (source)": src,
fsterr.AllowInstrumentation: true,
"Manifest (destination)": dst,
"Manifest (source)": src,
})

spinner.StopFailMessage(msg)
Expand Down Expand Up @@ -164,8 +169,9 @@ func (c *PackCommand) Exec(_ io.Reader, out io.Writer) (err error) {
dst := fmt.Sprintf("%s.tar.gz", dir)
if err = tar.Archive(src, dst); err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Tar source": dir,
"Tar destination": dst,
fsterr.AllowInstrumentation: true,
"Tar source": dir,
"Tar destination": dst,
})

spinner.StopFailMessage(msg)
Expand Down
5 changes: 3 additions & 2 deletions pkg/commands/compute/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) (err error) {
defer func() {
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
fsterr.AllowInstrumentation: true,
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
})
}
}()
Expand Down
6 changes: 4 additions & 2 deletions pkg/commands/compute/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ func (c *ValidateCommand) Exec(_ io.Reader, out io.Writer) error {
p, err := filepath.Abs(packagePath)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Path": c.path,
fsterr.AllowInstrumentation: true,
"Path": c.path,
})
return fmt.Errorf("error reading file path: %w", err)
}

if err := validate(p, nil); err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Path": c.path,
fsterr.AllowInstrumentation: true,
"Path": c.path,
})
return fsterr.RemediationError{
Inner: fmt.Errorf("failed to validate package: %w", err),
Expand Down
11 changes: 6 additions & 5 deletions pkg/commands/dictionary/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/errors"
fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
Expand Down Expand Up @@ -82,7 +82,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error {
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": errors.ServiceVersion(serviceVersion),
"Service Version": fsterr.ServiceVersion(serviceVersion),
})
return err
}
Expand All @@ -91,7 +91,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error {
c.input.ServiceVersion = serviceVersion.Number

if !c.newname.WasSet && !c.writeOnly.WasSet {
return errors.RemediationError{Inner: fmt.Errorf("error parsing arguments: required flag --new-name or --write-only not provided"), Remediation: "To fix this error, provide at least one of the aforementioned flags"}
return fsterr.RemediationError{Inner: fmt.Errorf("error parsing arguments: required flag --new-name or --write-only not provided"), Remediation: "To fix this error, provide at least one of the aforementioned flags"}
}

if c.newname.WasSet {
Expand All @@ -102,8 +102,9 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error {
writeOnly, err := strconv.ParseBool(c.writeOnly.Value)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
fsterr.AllowInstrumentation: true,
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
})
return err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/commands/logging/bigquery/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/logging/common"
"github.com/fastly/cli/pkg/errors"
fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
Expand Down Expand Up @@ -148,16 +148,17 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error {
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": errors.ServiceVersion(serviceVersion),
"Service Version": fsterr.ServiceVersion(serviceVersion),
})
return err
}

input, err := c.ConstructInput(serviceID, serviceVersion.Number)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
fsterr.AllowInstrumentation: true,
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
})
return err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/commands/logging/bigquery/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/logging/common"
"github.com/fastly/cli/pkg/errors"
fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
Expand Down Expand Up @@ -151,16 +151,17 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error {
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": errors.ServiceVersion(serviceVersion),
"Service Version": fsterr.ServiceVersion(serviceVersion),
})
return err
}

input, err := c.ConstructInput(serviceID, serviceVersion.Number)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
fsterr.AllowInstrumentation: true,
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
})
return err
}
Expand Down
Loading