From 26e79121f9cf962eeff362f26909727d20a0105a Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Thu, 11 Jan 2024 22:30:52 +0000 Subject: [PATCH] refactor: consistent naming for errors --- errors/errors_taskfile.go | 16 ++++++++-------- taskfile/reader.go | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/errors/errors_taskfile.go b/errors/errors_taskfile.go index ddfb7392..f080c4ef 100644 --- a/errors/errors_taskfile.go +++ b/errors/errors_taskfile.go @@ -107,20 +107,20 @@ func (err *TaskfileNotSecureError) Code() int { return CodeTaskfileNotSecure } -// TaskfileCacheNotFound is returned when the user attempts to use an offline +// TaskfileCacheNotFoundError is returned when the user attempts to use an offline // (cached) Taskfile but the files does not exist in the cache. -type TaskfileCacheNotFound struct { +type TaskfileCacheNotFoundError struct { URI string } -func (err *TaskfileCacheNotFound) Error() string { +func (err *TaskfileCacheNotFoundError) Error() string { return fmt.Sprintf( `task: Taskfile %q was not found in the cache. Remove the --offline flag to use a remote copy or download it using the --download flag`, err.URI, ) } -func (err *TaskfileCacheNotFound) Code() int { +func (err *TaskfileCacheNotFoundError) Code() int { return CodeTaskfileCacheNotFound } @@ -152,15 +152,15 @@ func (err *TaskfileVersionCheckError) Code() int { return CodeTaskfileVersionCheckError } -// TaskfileNetworkTimeout is returned when the user attempts to use a remote +// TaskfileNetworkTimeoutError is returned when the user attempts to use a remote // Taskfile but a network connection could not be established within the timeout. -type TaskfileNetworkTimeout struct { +type TaskfileNetworkTimeoutError struct { URI string Timeout time.Duration CheckedCache bool } -func (err *TaskfileNetworkTimeout) Error() string { +func (err *TaskfileNetworkTimeoutError) Error() string { var cacheText string if err.CheckedCache { cacheText = " and no offline copy was found in the cache" @@ -171,6 +171,6 @@ func (err *TaskfileNetworkTimeout) Error() string { ) } -func (err *TaskfileNetworkTimeout) Code() int { +func (err *TaskfileNetworkTimeoutError) Code() int { return CodeTaskfileNetworkTimeout } diff --git a/taskfile/reader.go b/taskfile/reader.go index 92784d6d..d07eb52e 100644 --- a/taskfile/reader.go +++ b/taskfile/reader.go @@ -189,7 +189,7 @@ func readTaskfile( // If the file is remote and we're in offline mode, check if we have a cached copy if node.Remote() && offline { if b, err = cache.read(node); errors.Is(err, os.ErrNotExist) { - return nil, &errors.TaskfileCacheNotFound{URI: node.Location()} + return nil, &errors.TaskfileCacheNotFoundError{URI: node.Location()} } else if err != nil { return nil, err } @@ -207,11 +207,11 @@ func readTaskfile( if node.Remote() && errors.Is(ctx.Err(), context.DeadlineExceeded) { // If a download was requested, then we can't use a cached copy if download { - return nil, &errors.TaskfileNetworkTimeout{URI: node.Location(), Timeout: timeout} + return nil, &errors.TaskfileNetworkTimeoutError{URI: node.Location(), Timeout: timeout} } // Search for any cached copies if b, err = cache.read(node); errors.Is(err, os.ErrNotExist) { - return nil, &errors.TaskfileNetworkTimeout{URI: node.Location(), Timeout: timeout, CheckedCache: true} + return nil, &errors.TaskfileNetworkTimeoutError{URI: node.Location(), Timeout: timeout, CheckedCache: true} } else if err != nil { return nil, err }