errors

package
v1.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2022 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthRemediation = fmt.Sprintf(strings.Join([]string{
	"This error may be caused by a missing, incorrect, or expired Fastly API token.",
	"Check that you're supplying a valid token, either via --token,",
	"through the environment variable %s, or through the config file via `fastly configure`.",
	"Verify that the token is still valid via `fastly whoami`.",
}, " "), env.Token)

AuthRemediation suggests checking the provided --token.

View Source
var AutoCloneRemediation = strings.Join([]string{
	"Repeat the command with the --autoclone flag to allow the version to be cloned",
}, " ")

AutoCloneRemediation suggests provide an --autoclone flag.

View Source
var BugRemediation = strings.Join([]string{
	"If you believe this error is the result of a bug, please file an issue:",
	"https://github.com/fastly/cli/issues/new?labels=bug&template=bug_report.md",
}, " ")

BugRemediation suggests filing a bug on the GitHub repo. It's good to include as the final suggested remediation in many errors.

View Source
var CLIUpdateRemediation = strings.Join([]string{
	"Please try updating the installed CLI version using:",
	"`fastly update`.",
	BugRemediation,
}, " ")

CLIUpdateRemediation suggests updating the installed CLI version.

View Source
var ComputeBuildRemediation = strings.Join([]string{
	"Add a [scripts.build] setting for your custom build process.",
	"See more at https://developer.fastly.com/reference/fastly-toml/",
}, " ")

ComputeBuildRemediation suggests configuring a `[scripts.build]` setting in the fastly.toml manifest.

View Source
var ComputeInitRemediation = strings.Join([]string{
	"Run `fastly compute init` to ensure a correctly configured manifest.",
	"See more at https://developer.fastly.com/reference/fastly-toml/",
}, " ")

ComputeInitRemediation suggests re-running `compute init` to resolve manifest issue.

View Source
var ComputeServeRemediation = strings.Join([]string{
	"The --watch flag enables hot reloading of your project to support a faster feedback loop during local development, and subsequently conflicts with the --skip-build flag which avoids rebuilding your project altogether.",
	"Remove one of the flags based on the outcome you require.",
}, " ")

ComputeServeRemediation suggests re-running `compute serve` with one of the incompatible flags removed.

View Source
var ComputeTrialRemediation = "For more help with this error see fastly.help/cli/ecp-feature"

ComputeTrialRemediation suggests contacting customer manager to enable the free trial feature flag.

View Source
var ConfigRemediation = strings.Join([]string{
	"There is a fallback version of the configuration provided with the CLI install",
	"(see `fastly configure --display`) which enables the CLI to continue to be usable even though the config couldn't be updated.",
}, " ")

ConfigRemediation informs the user that an error with loading the config isn't a breaking error and the CLI can still be used.

View Source
var CustomerIDRemediation = strings.Join([]string{
	"Please provide one via the --customer-id flag, or by setting the FASTLY_CUSTOMER_ID environment variable",
}, " ")

CustomerIDRemediation suggests provide a customer ID via --customer-id flag or via environment variable.

View Source
var ErrBuildStopped = RemediationError{
	Inner:       fmt.Errorf("build process stopped by user"),
	Remediation: "Remove or update the custom [scripts.build] in the fastly.toml manifest.",
}

ErrBuildStopped means the user stopped the build because they were unhappy with the custom build defined in the fastly.toml manifest file.

View Source
var ErrIncompatibleManifestVersion = RemediationError{
	Inner:       fmt.Errorf("the fastly.toml contains an incompatible manifest_version number"),
	Remediation: "Update the `manifest_version` in the fastly.toml and refer to https://github.com/fastly/cli/releases/tag/v0.39.3 for changes to the manifest structure",
}

ErrIncompatibleManifestVersion means the manifest_version defined is no longer compatible with the current CLI version.

View Source
var ErrIncompatibleServeFlags = RemediationError{
	Inner:       fmt.Errorf("--skip-build shouldn't be used with --watch"),
	Remediation: ComputeServeRemediation,
}

ErrIncompatibleServeFlags means no --skip-build can't be used with --watch because it defeats the purpose of --watch which is designed to restart Viceroy whenever changes are detected (those changes would not be seen if we allowed --skip-build with --watch).

View Source
var ErrInvalidArchive = RemediationError{
	Inner:       fmt.Errorf("invalid package archive structure"),
	Remediation: "Ensure the archive contains all required package files (such as a 'fastly.toml' manifest, and a 'src' folder etc).",
}

ErrInvalidArchive means the package archive didn't contain a recognised directory structure.

View Source
var ErrInvalidManifestVersion = RemediationError{
	Inner:       fmt.Errorf("failed to parse fastly.toml when checking if manifest_version was valid"),
	Remediation: "Delete `[manifest_version]` from the fastly.toml if present",
}

ErrInvalidManifestVersion means the manifest_version is defined as a toml section.

View Source
var ErrInvalidVerboseJSONCombo = RemediationError{
	Inner:       fmt.Errorf("invalid flag combination, --verbose and --json"),
	Remediation: "Use either --verbose or --json, not both.",
}

ErrInvalidVerboseJSONCombo means the user provided both a --verbose and --json flag which are mutally exclusive behaviours.

View Source
var ErrMissingManifestVersion = RemediationError{
	Inner:       fmt.Errorf("no manifest_version found in the fastly.toml"),
	Remediation: BugRemediation,
}

ErrMissingManifestVersion means an invalid manifest (fastly.toml) has been used.

View Source
var ErrNoCustomerID = RemediationError{
	Inner:       fmt.Errorf("error reading customer ID: no customer ID found"),
	Remediation: CustomerIDRemediation,
}

ErrNoCustomerID means no --customer-id or FASTLY_CUSTOMER_ID environment variable found.

View Source
var ErrNoID = RemediationError{
	Inner:       fmt.Errorf("no ID found"),
	Remediation: IDRemediation,
}

ErrNoID means no --id value has been provided.

View Source
var ErrNoServiceID = RemediationError{
	Inner:       fmt.Errorf("error reading service: no service ID found"),
	Remediation: ServiceIDRemediation,
}

ErrNoServiceID means no --service-id or service_id package manifest value has been provided.

View Source
var ErrNoToken = RemediationError{
	Inner:       fmt.Errorf("no token provided"),
	Remediation: AuthRemediation,
}

ErrNoToken means no --token has been provided.

View Source
var ErrParsingManifest = RemediationError{
	Inner:       fmt.Errorf("error parsing package manifest"),
	Remediation: ComputeInitRemediation,
}

ErrParsingManifest means there was a problem unmarshalling the package manifest.

View Source
var ErrReadingManifest = RemediationError{
	Inner:       fmt.Errorf("error reading package manifest"),
	Remediation: ComputeInitRemediation,
}

ErrReadingManifest means there was a problem reading the package manifest.

View Source
var ErrSignalInterrupt = fmt.Errorf("a SIGINT was received")

ErrSignalInterrupt means a SIGINT was received.

View Source
var ErrSignalKilled = fmt.Errorf("a SIGTERM was received")

ErrSignalKilled means a SIGTERM was received.

View Source
var ErrStopWalk = errors.New("stop directory walking")

ErrStopWalk is used to indicate to filepath.WalkDir that it should stop walking the directory tree.

View Source
var ErrUnrecognisedManifestVersion = RemediationError{
	Inner:       fmt.Errorf("unrecognised manifest_version found in the fastly.toml"),
	Remediation: CLIUpdateRemediation,
}

ErrUnrecognisedManifestVersion means an invalid manifest (fastly.toml) version has been specified.

View Source
var ErrViceroyRestart = fmt.Errorf("a RESTART was initiated")

ErrViceroyRestart means the viceroy binary needs to be restarted due to a file modification noticed while running `compute serve --watch`.

View Source
var ExistingDirRemediation = strings.Join([]string{
	"Please create a new directory and initialize a new project using:",
	"`fastly compute init`.",
}, " ")

ExistingDirRemediation suggests moving to another directory and retrying.

View Source
var FileRotationSize int64 = 5242880 // 5mb

FileRotationSize represents the size the log file needs to be before we truncate it.

NOTE: To enable easier testing of the log rotation logic, we don't define this as a constant but as a variable so the test file can mutate the value to something much smaller, meaning we can commit a small test file as part of the testing logic that will trigger a 'over the threshold' scenario.

View Source
var HostRemediation = strings.Join([]string{
	"This error may be caused by a problem with your host environment, for example",
	"too-restrictive file permissions, files that already exist, or a full disk.",
}, " ")

HostRemediation suggests there might be an issue with the local host.

View Source
var IDRemediation = strings.Join([]string{
	"Please provide one via the --id flag",
}, " ")

IDRemediation suggests an ID via --id flag should be provided.

Log is the primary interface for consumers.

View Source
var LogPath = func() string {
	if dir, err := os.UserConfigDir(); err == nil {
		return filepath.Join(dir, "fastly", "errors.log")
	}
	if dir, err := os.UserHomeDir(); err == nil {
		return filepath.Join(dir, ".fastly", "errors.log")
	}
	panic("unable to deduce user config dir or user home dir")
}()

LogPath is the location of the fastly CLI error log.

View Source
var NetworkRemediation = strings.Join([]string{
	"This error may be caused by transient network issues.",
	"Please verify your network connection and DNS configuration, and try again.",
}, " ")

NetworkRemediation suggests, somewhat unhelpfully, to try again later.

View Source
var Now = time.Now

Now is exposed so that we may mock it from our test file.

NOTE: The ideal way to deal with time is to inject it as a dependency and then the caller can provide a stubbed value, but in this case we don't want to have the CLI's business logic littered with lots of calls to time.Now() when that call can be handled internally by the .Add() method.

View Source
var PackageSizeRemediation = strings.Join([]string{
	"Please check our Compute@Edge resource limits:",
	"https://developer.fastly.com/learning/compute/#limitations-and-constraints",
}, " ")

PackageSizeRemediation suggests checking the resources documentation for the current package size limit.

View Source
var ServiceIDRemediation = strings.Join([]string{
	"Please provide one via the --service-id or --service-name flag, or by setting the FASTLY_SERVICE_ID environment variable, or within your package manifest",
}, " ")

ServiceIDRemediation suggests provide a service ID via --service-id flag or package manifest.

Functions

func ServiceVersion added in v0.36.0

func ServiceVersion(v *fastly.Version) (sv int)

ServiceVersion returns an integer regardless of whether the given argument is a nil pointer or not. It helps to reduce the boilerplate found across the codebase when tracking errors related to `cmd.ServiceDetails`.

func SimplifyFastlyError

func SimplifyFastlyError(httpError fastly.HTTPError) error

SimplifyFastlyError reduces the potentially complex and multi-line Error rendering of a fastly.HTTPError to something more palatable for a CLI.

Types

type Caller added in v0.36.0

type Caller struct {
	File string
	Line int
}

Caller represents where an error occurred.

type LogEntries added in v0.36.0

type LogEntries []LogEntry

LogEntries represents a list of recorded log entries.

func (*LogEntries) Add added in v0.36.0

func (l *LogEntries) Add(err error)

Add adds a new log entry.

func (*LogEntries) AddWithContext added in v0.36.0

func (l *LogEntries) AddWithContext(err error, ctx map[string]interface{})

AddWithContext adds a new log entry with extra contextual data.

func (LogEntries) Persist added in v0.36.0

func (l LogEntries) Persist(logPath string, args []string) error

Persist persists recorded log entries to disk.

type LogEntry added in v0.36.0

type LogEntry struct {
	Time    time.Time
	Err     error
	Caller  map[string]interface{}
	Context map[string]interface{}
}

LogEntry represents a single error log entry.

type LogInterface added in v0.36.0

type LogInterface interface {
	Add(err error)
	AddWithContext(err error, ctx map[string]interface{})
	Persist(logPath string, args []string) error
}

LogInterface represents the LogEntries behaviours.

type MockLog added in v1.3.0

type MockLog struct{}

MockLog is a no-op Log type.

func (MockLog) Add added in v1.3.0

func (ml MockLog) Add(err error)

func (MockLog) AddWithContext added in v1.3.0

func (ml MockLog) AddWithContext(err error, ctx map[string]interface{})

func (MockLog) Persist added in v1.3.0

func (ml MockLog) Persist(logPath string, args []string) error

type RemediationError

type RemediationError struct {
	Prefix      string
	Inner       error
	Remediation string
}

RemediationError wraps a normal error with a suggested remediation.

func Deduce

func Deduce(err error) RemediationError

Deduce attempts to deduce a RemediationError from a plain error. If the error is already a RemediationError it is returned directly. Certain deep error types, like a Fastly SDK HTTPError, are detected and converted in appropriate cases to e.g. AuthRemediation. If no specific remediation can be suggested, a remediation to file a bug is used.

func (RemediationError) Error

func (re RemediationError) Error() string

Error prints the inner error string without any remediation suggestion.

func (RemediationError) Print

func (re RemediationError) Print(w io.Writer)

Print the error to the io.Writer for human consumption. If a prefix is provided, it will be written without modification. The inner error is always printed via text.Output with an "Error: " prefix and a "." suffix. If a remediation is provided, it's printed via text.Output.

func (RemediationError) Unwrap

func (re RemediationError) Unwrap() error

Unwrap returns the inner error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL