errors

package
v0.39.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: Apache-2.0 Imports: 14 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 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 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 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 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 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 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 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 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