-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Error Handling and Logging Mechanism
Signed-off-by: vinayakjaas <[email protected]>
- Loading branch information
1 parent
c9c5870
commit bb9c8d9
Showing
3 changed files
with
77 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,64 @@ | ||
package errors | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
var FailedDownloadError = errors.New("failed to download dependency") | ||
var CheckSumMismatchError = errors.New("checksum mismatch") | ||
var FailedToVendorDependency = errors.New("failed to vendor dependency") | ||
var FailedToPackage = errors.New("failed to package.") | ||
var InvalidDependency = errors.New("invalid dependency.") | ||
var InternalBug = errors.New("internal bug, please contact us and we will fix the problem.") | ||
var FailedToLoadPackage = errors.New("failed to load package, please check the package path is valid.") | ||
// KpmError is a custom error type for kpm | ||
type KpmError struct { | ||
Message string | ||
Err error | ||
Context string | ||
} | ||
|
||
// Invalid Options Format Errors | ||
// Invalid 'kpm init' | ||
var InvalidInitOptions = errors.New("invalid 'kpm init' argument, you must provide a name for the package to be initialized.") | ||
func (e *KpmError) Error() string { | ||
return fmt.Sprintf("%s: %s - %v", e.Message, e.Context, e.Err) | ||
} | ||
|
||
// Invalid 'kpm add' | ||
var InvalidAddOptions = errors.New("invalid 'kpm add' argument, you must provide a package name or url for the package") | ||
var InvalidAddOptionsInvalidGitUrl = errors.New("invalid 'kpm add' argument, you must provide a Git Url for the package.") | ||
var InvalidAddOptionsInvalidOciRef = errors.New("invalid 'kpm add' argument, you must provide a valid Oci Ref for the package.") | ||
func NewKpmError(message string, err error, context string) error { | ||
return &KpmError{ | ||
Message: message, | ||
Err: err, | ||
Context: context, | ||
} | ||
} | ||
|
||
var InvalidAddOptionsInvalidOciReg = errors.New("invalid 'kpm add' argument, you must provide a Reg for the package.") | ||
var InvalidAddOptionsInvalidOciRepo = errors.New("invalid 'kpm add' argument, you must provide a Repo for the package.") | ||
|
||
// Invalid 'kpm update' | ||
var MultipleSources = errors.New("multiple sources found, there must be a single source.") | ||
|
||
// Invalid 'kpm run' | ||
var InvalidRunOptionsWithoutEntryFiles = errors.New("invalid 'kpm run' argument, you must provide an entry file.") | ||
var EntryFileNotFound = errors.New("entry file cannot be found, please make sure the '--input' entry file can be found") | ||
var CompileFailed = errors.New("failed to compile kcl.") | ||
var FailedUnTarKclPackage = errors.New("failed to untar kcl package, please re-download") | ||
var UnknownTarFormat = errors.New("unknown tar format.") | ||
var KclPacakgeTarNotFound = errors.New("the kcl package tar path is not found") | ||
var InvalidKclPacakgeTar = errors.New("the kcl package tar path is an invalid *.tar file") | ||
|
||
// Invalid KCL_PKG_PATH | ||
var InvalidKpmHomeInCurrentPkg = errors.New("environment variable KCL_PKG_PATH cannot be set to the same path as the current KCL package.") | ||
|
||
// Invalid oci | ||
var FailedLogin = errors.New("failed to login, please check registry, username and password is valid.") | ||
var FailedLogout = errors.New("failed to logout, the registry not logged in.") | ||
var FailedPull = errors.New("failed to pull kcl package") | ||
var FailedPushToOci = errors.New("failed to push kcl package tar to oci.") | ||
var InvalidOciRef = errors.New("invalid oci reference.") | ||
var NotOciUrl = errors.New("url is not an oci url.") | ||
var IsOciRef = errors.New("oci ref is not an url.") | ||
|
||
// Invalid Version | ||
var InvalidVersionFormat = errors.New("failed to parse version.") | ||
var PathNotFound = errors.New("path not found.") | ||
var PathIsEmpty = errors.New("path is empty.") | ||
var InvalidPkg = errors.New("invalid kcl package.") | ||
var InvalidOciUrl = errors.New("invalid oci url") | ||
var UnknownEnv = errors.New("invalid environment variable") | ||
|
||
// No kcl files | ||
var NoKclFiles = errors.New("No input KCL files") | ||
// Error variables | ||
var ( | ||
FailedDownloadError = NewKpmError("Operation failed", fmt.Errorf("failed to download dependency"), "") | ||
CheckSumMismatchError = NewKpmError("Operation failed", fmt.Errorf("checksum mismatch"), "") | ||
FailedToVendorDependency = NewKpmError("Operation failed", fmt.Errorf("failed to vendor dependency"), "") | ||
FailedToPackage = NewKpmError("Operation failed", fmt.Errorf("failed to package"), "") | ||
InvalidDependency = NewKpmError("Operation failed", fmt.Errorf("invalid dependency"), "") | ||
InternalBug = NewKpmError("Operation failed", fmt.Errorf("internal bug, please contact us and we will fix the problem"), "") | ||
FailedToLoadPackage = NewKpmError("Operation failed", fmt.Errorf("failed to load package, please check the package path is valid"), "") | ||
InvalidInitOptions = NewKpmError("Operation failed", fmt.Errorf("invalid 'kpm init' argument, you must provide a name for the package to be initialized"), "") | ||
InvalidAddOptions = NewKpmError("Operation failed", fmt.Errorf("invalid 'kpm add' argument, you must provide a package name or url for the package"), "") | ||
InvalidAddOptionsInvalidGitUrl = NewKpmError("Operation failed", fmt.Errorf("invalid 'kpm add' argument, you must provide a Git Url for the package"), "") | ||
InvalidAddOptionsInvalidOciRef = NewKpmError("Operation failed", fmt.Errorf("invalid 'kpm add' argument, you must provide a valid Oci Ref for the package"), "") | ||
InvalidAddOptionsInvalidOciReg = NewKpmError("Operation failed", fmt.Errorf("invalid 'kpm add' argument, you must provide a Reg for the package"), "") | ||
InvalidAddOptionsInvalidOciRepo = NewKpmError("Operation failed", fmt.Errorf("invalid 'kpm add' argument, you must provide a Repo for the package"), "") | ||
MultipleSources = NewKpmError("Operation failed", fmt.Errorf("multiple sources found, there must be a single source"), "") | ||
InvalidRunOptionsWithoutEntryFiles = NewKpmError("Operation failed", fmt.Errorf("invalid 'kpm run' argument, you must provide an entry file"), "") | ||
EntryFileNotFound = NewKpmError("Operation failed", fmt.Errorf("entry file cannot be found, please make sure the '--input' entry file can be found"), "") | ||
CompileFailed = NewKpmError("Operation failed", fmt.Errorf("failed to compile kcl"), "") | ||
FailedUnTarKclPackage = NewKpmError("Operation failed", fmt.Errorf("failed to untar kcl package, please re-download"), "") | ||
UnknownTarFormat = NewKpmError("Operation failed", fmt.Errorf("unknown tar format"), "") | ||
KclPacakgeTarNotFound = NewKpmError("Operation failed", fmt.Errorf("the kcl package tar path is not found"), "") | ||
InvalidKclPacakgeTar = NewKpmError("Operation failed", fmt.Errorf("the kcl package tar path is an invalid *.tar file"), "") | ||
InvalidKpmHomeInCurrentPkg = NewKpmError("Operation failed", fmt.Errorf("environment variable KCL_PKG_PATH cannot be set to the same path as the current KCL package"), "") | ||
FailedLogin = NewKpmError("Operation failed", fmt.Errorf("failed to login, please check registry, username and password is valid"), "") | ||
FailedLogout = NewKpmError("Operation failed", fmt.Errorf("failed to logout, the registry not logged in"), "") | ||
FailedPull = NewKpmError("Operation failed", fmt.Errorf("failed to pull kcl package"), "") | ||
FailedPushToOci = NewKpmError("Operation failed", fmt.Errorf("failed to push kcl package tar to oci"), "") | ||
InvalidOciRef = NewKpmError("Operation failed", fmt.Errorf("invalid oci reference"), "") | ||
NotOciUrl = NewKpmError("Operation failed", fmt.Errorf("url is not an oci url"), "") | ||
IsOciRef = NewKpmError("Operation failed", fmt.Errorf("oci ref is not an url"), "") | ||
InvalidVersionFormat = NewKpmError("Operation failed", fmt.Errorf("failed to parse version"), "") | ||
PathNotFound = NewKpmError("Operation failed", fmt.Errorf("path not found"), "") | ||
PathIsEmpty = NewKpmError("Operation failed", fmt.Errorf("path is empty"), "") | ||
InvalidPkg = NewKpmError("Operation failed", fmt.Errorf("invalid kcl package"), "") | ||
InvalidOciUrl = NewKpmError("Operation failed", fmt.Errorf("invalid oci url"), "") | ||
UnknownEnv = NewKpmError("Operation failed", fmt.Errorf("invalid environment variable"), "") | ||
NoKclFiles = NewKpmError("Operation failed", fmt.Errorf("No input KCL files"), "") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters