Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.
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.
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.
var CLIUpdateRemediation = strings.Join([]string{ "Please try updating the installed CLI version using:", "`fastly update`.", BugRemediation, }, " ")
CLIUpdateRemediation suggests updating the installed CLI version.
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.
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.
var ErrNoID = RemediationError{ Inner: fmt.Errorf("no ID found"), Remediation: IDRemediation, }
ErrNoID means no --id value has been provided.
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.
var ErrNoToken = RemediationError{ Inner: fmt.Errorf("no token provided"), Remediation: AuthRemediation, }
ErrNoToken means no --token has been provided.
var ErrSignalInterrupt = fmt.Errorf("a SIGINT was received")
ErrSignalInterrupt means a SIGINT was received.
var ErrSignalKilled = fmt.Errorf("a SIGTERM was received")
ErrSignalKilled means a SIGTERM was received.
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.
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.
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.
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.
var IDRemediation = strings.Join([]string{
"Please provide one via the --id flag",
}, " ")
IDRemediation suggests an ID via --id flag should be provided.
var Log = new(LogEntries)
Log is the primary interface for consumers.
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.
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.
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.
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.
var ServiceIDRemediation = strings.Join([]string{
"Please provide one via the --service-id 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
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 ¶
SimplifyFastlyError reduces the potentially complex and multi-line Error rendering of a fastly.HTTPError to something more palatable for a CLI.
Types ¶
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.
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 RemediationError ¶
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.