From da3890eeb4aec2b0b600ed33b7ff3bf1f6a1a351 Mon Sep 17 00:00:00 2001 From: zongz Date: Mon, 20 Nov 2023 15:00:38 +0800 Subject: [PATCH] fix: throw all errors from low level Signed-off-by: zongz --- pkg/api/kpm_run.go | 15 ++++++---- pkg/api/kpm_run_test.go | 3 +- pkg/client/client.go | 30 +++++++++++-------- pkg/client/client_test.go | 16 ++-------- pkg/cmd/cmd_import.go | 5 ++-- pkg/cmd/cmd_init.go | 2 +- pkg/cmd/cmd_metadata.go | 3 +- pkg/cmd/cmd_pkg.go | 5 ++-- pkg/cmd/cmd_push.go | 6 ++-- pkg/cmd/cmd_update.go | 3 +- pkg/oci/oci.go | 17 +++++++---- pkg/oci/oci_test.go | 3 +- pkg/package/package.go | 4 +-- pkg/reporter/reporter.go | 4 +++ pkg/runner/entry.go | 4 +-- pkg/settings/settings.go | 2 +- pkg/utils/utils.go | 16 +++++----- .../add_path_not_exist/test_suite.stderr | 2 +- .../add_exist_not_pkgpath/test_suite.stderr | 2 +- .../add_path_not_exist/test_suite.stderr | 2 +- .../add_with_name_outside/test_suite.stderr | 2 +- .../test_suite.stderr | 2 +- .../test_suite.stderr | 2 +- .../test_suite.stderr | 3 +- .../test_suite.stderr | 3 +- .../test_suite.stderr | 3 +- .../run_with_no_args/test_suite.stderr | 3 +- 27 files changed, 86 insertions(+), 76 deletions(-) diff --git a/pkg/api/kpm_run.go b/pkg/api/kpm_run.go index 5b2c29ad..d2eb067c 100644 --- a/pkg/api/kpm_run.go +++ b/pkg/api/kpm_run.go @@ -1,7 +1,6 @@ package api import ( - "fmt" "os" "path/filepath" "strings" @@ -118,7 +117,7 @@ func RunCurrentPkg(opts *opt.CompileOptions) (*kcl.KCLResultList, error) { opts.SetPkgPath(pwd) if err != nil { - reporter.ExitWithReport("kpm: internal bug: failed to load working directory") + return nil, reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, failed to load working directory.") } return RunPkgWithOpt(opts) @@ -168,7 +167,7 @@ func RunOciPkg(ociRef, version string, opts *opt.CompileOptions) (*kcl.KCLResult // 1. Create the temporary directory to pull the tar. tmpDir, err := os.MkdirTemp("", "") if err != nil { - return nil, errors.InternalBug + return nil, reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, please contact us to fix it.") } // clean the temp dir. defer os.RemoveAll(tmpDir) @@ -185,7 +184,11 @@ func RunOciPkg(ociRef, version string, opts *opt.CompileOptions) (*kcl.KCLResult // 3.Get the (*.tar) file path. matches, err := filepath.Glob(filepath.Join(localPath, constants.KCL_PKG_TAR)) if err != nil || len(matches) != 1 { - return nil, errors.FailedPull + if err != nil { + return nil, reporter.NewErrorEvent(reporter.FailedGetPkg, err, "failed to pull kcl package") + } else { + return nil, errors.FailedPull + } } // 4. Untar the tar file. @@ -210,12 +213,12 @@ func RunOciPkg(ociRef, version string, opts *opt.CompileOptions) (*kcl.KCLResult func run(kpmcli *client.KpmClient, opts *opt.CompileOptions) (*kcl.KCLResultList, error) { pkgPath, err := filepath.Abs(opts.PkgPath()) if err != nil { - return nil, errors.InternalBug + return nil, reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, please contact us to fix it.") } kclPkg, err := pkg.LoadKclPkg(pkgPath) if err != nil { - return nil, fmt.Errorf("kpm: failed to load package, please check the package path '%s' is valid", pkgPath) + return nil, err } kclPkg.SetVendorMode(opts.IsVendor()) diff --git a/pkg/api/kpm_run_test.go b/pkg/api/kpm_run_test.go index ac77eeb2..58e2f53b 100644 --- a/pkg/api/kpm_run_test.go +++ b/pkg/api/kpm_run_test.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -70,7 +71,7 @@ func TestRunPkgInPathInvalidPkg(t *testing.T) { opts.Merge(kcl.WithKFilenames(filepath.Join(pkgPath, "invalid_pkg", "not_exist.k"))) result, err := RunPkgInPath(opts) assert.NotEqual(t, err, nil) - assert.Equal(t, err.Error(), fmt.Sprintf("kpm: failed to load package, please check the package path '%s' is valid", pkgPath)) + assert.Equal(t, true, strings.Contains(err.Error(), fmt.Sprintf("kpm: could not load 'kcl.mod' in '%s'\n", pkgPath))) assert.Equal(t, result, "") } diff --git a/pkg/client/client.go b/pkg/client/client.go index 60b03579..4de108cd 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -87,14 +87,14 @@ func (c *KpmClient) GetSettings() *settings.Settings { func (c *KpmClient) LoadPkgFromPath(pkgPath string) (*pkg.KclPkg, error) { modFile, err := c.LoadModFile(pkgPath) if err != nil { - return nil, reporter.NewErrorEvent(reporter.FailedLoadKclMod, err, fmt.Sprintf("could not load 'kcl.mod' in '%s'.", pkgPath)) + return nil, reporter.NewErrorEvent(reporter.FailedLoadKclMod, err, fmt.Sprintf("could not load 'kcl.mod' in '%s'", pkgPath)) } // Get dependencies from kcl.mod.lock. deps, err := c.LoadLockDeps(pkgPath) if err != nil { - return nil, reporter.NewErrorEvent(reporter.FailedLoadKclMod, err, fmt.Sprintf("could not load 'kcl.mod.lock' in '%s'.", pkgPath)) + return nil, reporter.NewErrorEvent(reporter.FailedLoadKclMod, err, fmt.Sprintf("could not load 'kcl.mod.lock' in '%s'", pkgPath)) } return &pkg.KclPkg{ @@ -271,7 +271,7 @@ func (c *KpmClient) ResolveDepsMetadataInJsonStr(kclPkg *pkg.KclPkg, update bool // 2. Serialize to JSON jsonData, err := json.Marshal(kclPkg.Dependencies) if err != nil { - return "", errors.InternalBug + return "", reporter.NewErrorEvent(reporter.Bug, err, "internal bug: failed to marshal the dependencies into json") } return string(jsonData), nil @@ -299,12 +299,12 @@ func (c *KpmClient) Compile(kclPkg *pkg.KclPkg, kclvmCompiler *runner.Compiler) func (c *KpmClient) CompileWithOpts(opts *opt.CompileOptions) (*kcl.KCLResultList, error) { pkgPath, err := filepath.Abs(opts.PkgPath()) if err != nil { - return nil, errors.InternalBug + return nil, reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, please contact us to fix it.") } kclPkg, err := pkg.LoadKclPkg(pkgPath) if err != nil { - return nil, fmt.Errorf("kpm: failed to load package, please check the package path '%s' is valid", pkgPath) + return nil, err } kclPkg.SetVendorMode(opts.IsVendor()) @@ -417,7 +417,7 @@ func (c *KpmClient) CompileOciPkg(ociSource, version string, opts *opt.CompileOp // 1. Create the temporary directory to pull the tar. tmpDir, err := os.MkdirTemp("", "") if err != nil { - return nil, errors.InternalBug + return nil, reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, please contact us to fix it.") } // clean the temp dir. defer os.RemoveAll(tmpDir) @@ -434,7 +434,11 @@ func (c *KpmClient) CompileOciPkg(ociSource, version string, opts *opt.CompileOp // 3.Get the (*.tar) file path. matches, err := filepath.Glob(filepath.Join(localPath, constants.KCL_PKG_TAR)) if err != nil || len(matches) != 1 { - return nil, errors.FailedPull + if err != nil { + return nil, reporter.NewErrorEvent(reporter.FailedGetPkg, err, "failed to pull kcl package") + } else { + return nil, errors.FailedPull + } } return c.CompileTarPkg(matches[0], opts) @@ -572,14 +576,14 @@ func (c *KpmClient) Package(kclPkg *pkg.KclPkg, tarPath string, vendorMode bool) if vendorMode { err := c.VendorDeps(kclPkg) if err != nil { - return errors.FailedToVendorDependency + return reporter.NewErrorEvent(reporter.FailedVendor, err, "failed to vendor dependencies") } } // Tar the current kcl package into a "*.tar" file. err := utils.TarDir(kclPkg.HomePath, tarPath) if err != nil { - return errors.FailedToPackage + return reporter.NewErrorEvent(reporter.FailedPackage, err, "failed to package the kcl module") } return nil } @@ -616,24 +620,24 @@ func (c *KpmClient) VendorDeps(kclPkg *pkg.KclPkg) error { // If there is, copy it into the 'vendor' directory. err := copy.Copy(cacheFullPath, vendorFullPath) if err != nil { - return errors.FailedToVendorDependency + return err } } else if utils.DirExists(d.GetLocalFullPath(kclPkg.HomePath)) && check(d, d.GetLocalFullPath(kclPkg.HomePath)) { // If there is, copy it into the 'vendor' directory. err := copy.Copy(d.GetLocalFullPath(kclPkg.HomePath), vendorFullPath) if err != nil { - return errors.FailedToVendorDependency + return err } } else { // re-download if not. err = c.AddDepToPkg(kclPkg, &d) if err != nil { - return errors.FailedToVendorDependency + return err } // re-vendor again with new kcl.mod and kcl.mod.lock err = c.VendorDeps(kclPkg) if err != nil { - return errors.FailedToVendorDependency + return err } return nil } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index e70723d3..cf045a15 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -124,10 +124,7 @@ func TestInitEmptyPkg(t *testing.T) { assert.Equal(t, err, nil) testKclPkg, err := pkg.LoadKclPkg(testDir) - if err != nil { - t.Errorf("Failed to 'LoadKclPkg'.") - } - + assert.Equal(t, err, nil) assert.Equal(t, testKclPkg.ModFile.Pkg.Name, "test_name") assert.Equal(t, testKclPkg.ModFile.Pkg.Version, "0.0.1") assert.Equal(t, testKclPkg.ModFile.Pkg.Edition, "0.0.1") @@ -180,16 +177,9 @@ func TestUpdateKclModAndLock(t *testing.T) { kclPkg.ModFile.Dependencies.Deps["test"] = dep err = kclPkg.ModFile.StoreModFile() - - if err != nil { - t.Errorf("failed to LockDepsVersion.") - } - + assert.Equal(t, err, nil) err = kclPkg.LockDepsVersion() - - if err != nil { - t.Errorf("failed to LockDepsVersion.") - } + assert.Equal(t, err, nil) expectDir := getTestDir("expected") diff --git a/pkg/cmd/cmd_import.go b/pkg/cmd/cmd_import.go index 601ec956..8f9e39d1 100644 --- a/pkg/cmd/cmd_import.go +++ b/pkg/cmd/cmd_import.go @@ -4,11 +4,12 @@ package cmd import ( "fmt" + "os" + "github.com/urfave/cli/v2" "kcl-lang.io/kcl-go/pkg/tools/gen" "kcl-lang.io/kpm/pkg/client" "kcl-lang.io/kpm/pkg/reporter" - "os" ) // NewImportCmd new a Command for `kpm import`. @@ -82,7 +83,7 @@ func NewImportCmd(kpmcli *client.KpmClient) *cli.Command { outputWriter, err := os.Create(outputFile) if err != nil { - return fmt.Errorf("kpm: failed to create output file: %s", outputFile) + return reporter.NewErrorEvent(reporter.FailedCreateFile, err, fmt.Sprintf("failed to create output file: %s", outputFile)) } return gen.GenKcl(outputWriter, inputFile, nil, opt) diff --git a/pkg/cmd/cmd_init.go b/pkg/cmd/cmd_init.go index d7979a9b..4251147c 100644 --- a/pkg/cmd/cmd_init.go +++ b/pkg/cmd/cmd_init.go @@ -25,7 +25,7 @@ func NewInitCmd(kpmcli *client.KpmClient) *cli.Command { pwd, err := os.Getwd() if err != nil { - reporter.Fatal("kpm: internal bugs, please contact us to fix it") + return reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, failed to load working directory.") } var pkgName string diff --git a/pkg/cmd/cmd_metadata.go b/pkg/cmd/cmd_metadata.go index ebb7b367..2f36c1b4 100644 --- a/pkg/cmd/cmd_metadata.go +++ b/pkg/cmd/cmd_metadata.go @@ -9,7 +9,6 @@ import ( "github.com/urfave/cli/v2" "kcl-lang.io/kpm/pkg/client" "kcl-lang.io/kpm/pkg/env" - "kcl-lang.io/kpm/pkg/errors" pkg "kcl-lang.io/kpm/pkg/package" "kcl-lang.io/kpm/pkg/reporter" ) @@ -53,7 +52,7 @@ func NewMetadataCmd(kpmcli *client.KpmClient) *cli.Command { pwd, err := os.Getwd() if err != nil { - return errors.InternalBug + return reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, please contact us to fix it") } kclPkg, err := pkg.LoadKclPkg(pwd) diff --git a/pkg/cmd/cmd_pkg.go b/pkg/cmd/cmd_pkg.go index 7b53fbce..23534fc0 100644 --- a/pkg/cmd/cmd_pkg.go +++ b/pkg/cmd/cmd_pkg.go @@ -9,7 +9,6 @@ import ( "github.com/urfave/cli/v2" "kcl-lang.io/kpm/pkg/client" - "kcl-lang.io/kpm/pkg/errors" pkg "kcl-lang.io/kpm/pkg/package" "kcl-lang.io/kpm/pkg/reporter" "kcl-lang.io/kpm/pkg/utils" @@ -48,7 +47,7 @@ func NewPkgCmd(kpmcli *client.KpmClient) *cli.Command { pwd, err := os.Getwd() if err != nil { - reporter.ExitWithReport("kpm: internal bug: failed to load working directory") + return reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, failed to load working directory.") } kclPkg, err := pkg.LoadKclPkg(pwd) @@ -62,7 +61,7 @@ func NewPkgCmd(kpmcli *client.KpmClient) *cli.Command { if !utils.DirExists(tarPath) { err := os.MkdirAll(tarPath, os.ModePerm) if err != nil { - return errors.InternalBug + return reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, failed to create the target directory") } } diff --git a/pkg/cmd/cmd_push.go b/pkg/cmd/cmd_push.go index a7477fe3..bf3bc6b6 100644 --- a/pkg/cmd/cmd_push.go +++ b/pkg/cmd/cmd_push.go @@ -109,7 +109,7 @@ func pushTarPackage(ociUrl, localTarPath string, vendorMode bool, kpmcli *client if kclPkg != nil && utils.DirExists(kclPkg.HomePath) { err = os.RemoveAll(kclPkg.HomePath) if err != nil { - err = errors.InternalBug + err = reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, failed to clean the temp dir.") } } }() @@ -141,7 +141,7 @@ func pushPackage(ociUrl string, kclPkg *pkg.KclPkg, vendorMode bool, kpmcli *cli if kclPkg != nil && utils.DirExists(tarPath) { err = os.RemoveAll(tarPath) if err != nil { - err = errors.InternalBug + err = reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, failed to clean the temp dir.") } } }() @@ -167,7 +167,7 @@ func pushPackage(ociUrl string, kclPkg *pkg.KclPkg, vendorMode bool, kpmcli *cli "only support url scheme 'oci://'.", ) } - + ociOpts.Annotations, err = oci.GenOciManifestFromPkg(kclPkg) if err != nil { return err diff --git a/pkg/cmd/cmd_update.go b/pkg/cmd/cmd_update.go index 012ff83c..5f7cafd2 100644 --- a/pkg/cmd/cmd_update.go +++ b/pkg/cmd/cmd_update.go @@ -8,7 +8,6 @@ import ( "github.com/urfave/cli/v2" "kcl-lang.io/kpm/pkg/client" "kcl-lang.io/kpm/pkg/env" - "kcl-lang.io/kpm/pkg/errors" "kcl-lang.io/kpm/pkg/reporter" ) @@ -45,7 +44,7 @@ func KpmUpdate(c *cli.Context, kpmcli *client.KpmClient) error { if len(input_paths) == 0 { pwd, err := os.Getwd() if err != nil { - return errors.InternalBug + return reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, please contact us to fix it") } pkg_paths = append(pkg_paths, pwd) } else { diff --git a/pkg/oci/oci.go b/pkg/oci/oci.go index 1618c222..5d8f690b 100644 --- a/pkg/oci/oci.go +++ b/pkg/oci/oci.go @@ -9,7 +9,6 @@ import ( v1 "github.com/opencontainers/image-spec/specs-go/v1" "github.com/thoas/go-funk" "kcl-lang.io/kpm/pkg/constants" - "kcl-lang.io/kpm/pkg/errors" "kcl-lang.io/kpm/pkg/opt" pkg "kcl-lang.io/kpm/pkg/package" "kcl-lang.io/kpm/pkg/reporter" @@ -36,7 +35,11 @@ func Login(hostname, username, password string, setting *settings.Settings) erro authClient, err := dockerauth.NewClientWithDockerFallback(setting.CredentialsFile) if err != nil { - return errors.FailedLogin + return reporter.NewErrorEvent( + reporter.FailedLogin, + err, + fmt.Sprintf("failed to login '%s', please check registry, username and password is valid", hostname), + ) } err = authClient.LoginWithOpts( @@ -48,7 +51,11 @@ func Login(hostname, username, password string, setting *settings.Settings) erro ) if err != nil { - return errors.FailedLogin + return reporter.NewErrorEvent( + reporter.FailedLogin, + err, + fmt.Sprintf("failed to login '%s', please check registry, username and password is valid", hostname), + ) } return nil @@ -60,13 +67,13 @@ func Logout(hostname string, setting *settings.Settings) error { authClient, err := dockerauth.NewClientWithDockerFallback(setting.CredentialsFile) if err != nil { - return errors.FailedLogout + return reporter.NewErrorEvent(reporter.FailedLogout, err, fmt.Sprintf("failed to logout '%s'", hostname)) } err = authClient.Logout(context.Background(), hostname) if err != nil { - return errors.FailedLogout + return reporter.NewErrorEvent(reporter.FailedLogout, err, fmt.Sprintf("failed to logout '%s'", hostname)) } return nil diff --git a/pkg/oci/oci_test.go b/pkg/oci/oci_test.go index 9f12905c..21f4a35e 100644 --- a/pkg/oci/oci_test.go +++ b/pkg/oci/oci_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "kcl-lang.io/kpm/pkg/errors" "kcl-lang.io/kpm/pkg/settings" "kcl-lang.io/kpm/pkg/utils" ) @@ -39,5 +38,5 @@ func TestLogin(t *testing.T) { userPwd := "invalid_password" err := Login(hostName, userName, userPwd, &settings) - assert.Equal(t, err, errors.FailedLogin) + assert.Equal(t, err.Error(), "kpm: failed to login 'ghcr.io', please check registry, username and password is valid\nkpm: Get \"https://ghcr.io/v2/\": denied: denied\n") } diff --git a/pkg/package/package.go b/pkg/package/package.go index de762f08..beff8eb4 100644 --- a/pkg/package/package.go +++ b/pkg/package/package.go @@ -32,14 +32,14 @@ func NewKclPkg(opts *opt.InitOptions) KclPkg { func LoadKclPkg(pkgPath string) (*KclPkg, error) { modFile, err := LoadModFile(pkgPath) if err != nil { - return nil, reporter.NewErrorEvent(reporter.FailedLoadKclMod, err, fmt.Sprintf("could not load 'kcl.mod' in '%s'.", pkgPath)) + return nil, reporter.NewErrorEvent(reporter.FailedLoadKclMod, err, fmt.Sprintf("could not load 'kcl.mod' in '%s'", pkgPath)) } // Get dependencies from kcl.mod.lock. deps, err := LoadLockDeps(pkgPath) if err != nil { - return nil, reporter.NewErrorEvent(reporter.FailedLoadKclMod, err, fmt.Sprintf("could not load 'kcl.mod.lock' in '%s'.", pkgPath)) + return nil, reporter.NewErrorEvent(reporter.FailedLoadKclMod, err, fmt.Sprintf("could not load 'kcl.mod.lock' in '%s'", pkgPath)) } return &KclPkg{ diff --git a/pkg/reporter/reporter.go b/pkg/reporter/reporter.go index 95b21a36..527acb15 100644 --- a/pkg/reporter/reporter.go +++ b/pkg/reporter/reporter.go @@ -59,6 +59,7 @@ const ( FailedCreateStorePath FailedPush FailedGetPkg + FailedVendor FailedAccessPkgPath UnKnownPullWhat UnknownEnv @@ -67,6 +68,9 @@ const ( FailedLoadKclMod FailedLoadKclModLock FailedCreateFile + FailedPackage + FailedLogin + FailedLogout FileExists CheckSumMismatch CalSumFailed diff --git a/pkg/runner/entry.go b/pkg/runner/entry.go index ce230a69..ea69eeef 100644 --- a/pkg/runner/entry.go +++ b/pkg/runner/entry.go @@ -178,7 +178,7 @@ func GetSourceKindFrom(source string) EntryKind { func FindModRootFrom(startPath string) (string, *reporter.KpmEvent) { info, err := os.Stat(startPath) if err != nil { - return "", reporter.NewErrorEvent(reporter.CompileFailed, fmt.Errorf("failed to access path '%s'", startPath)) + return "", reporter.NewErrorEvent(reporter.CompileFailed, err, fmt.Sprintf("failed to access path '%s'", startPath)) } var start string // If the start path is a kcl file, find from the parent dir of the kcl file. @@ -188,7 +188,7 @@ func FindModRootFrom(startPath string) (string, *reporter.KpmEvent) { // If the start path is a dir, find from the start path. start = startPath } else { - return "", reporter.NewErrorEvent(reporter.CompileFailed, fmt.Errorf("invalid file path '%s'", startPath)) + return "", reporter.NewErrorEvent(reporter.CompileFailed, err, fmt.Sprintf("invalid file path '%s'", startPath)) } if _, err := os.Stat(filepath.Join(start, constants.KCL_MOD)); err == nil { diff --git a/pkg/settings/settings.go b/pkg/settings/settings.go index 8b370cac..56a873e5 100644 --- a/pkg/settings/settings.go +++ b/pkg/settings/settings.go @@ -187,7 +187,7 @@ func isOn(input string) (bool, *reporter.KpmEvent) { func GetFullPath(jsonFileName string) (string, error) { home, err := env.GetAbsPkgPath() if err != nil { - return "", errors.InternalBug + return "", reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, failed to load working directory") } return filepath.Join(home, jsonFileName), nil diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 49e88bb6..dcf83873 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -183,7 +183,7 @@ func TarDir(srcDir string, tarPath string) error { func UnTarDir(tarPath string, destDir string) error { file, err := os.Open(tarPath) if err != nil { - return errors.KclPacakgeTarNotFound + return reporter.NewErrorEvent(reporter.FailedCreateFile, err, fmt.Sprintf("failed to open '%s'", tarPath)) } defer file.Close() @@ -195,7 +195,7 @@ func UnTarDir(tarPath string, destDir string) error { break } if err != nil { - return errors.FailedUnTarKclPackage + return reporter.NewErrorEvent(reporter.FailedCreateFile, err, fmt.Sprintf("failed to open '%s'", tarPath)) } destFilePath := filepath.Join(destDir, header.Name) @@ -211,12 +211,12 @@ func UnTarDir(tarPath string, destDir string) error { } outFile, err := os.Create(destFilePath) if err != nil { - return errors.FailedUnTarKclPackage + return reporter.NewErrorEvent(reporter.FailedCreateFile, err, fmt.Sprintf("failed to open '%s'", tarPath)) } defer outFile.Close() if _, err := io.Copy(outFile, tarReader); err != nil { - return errors.FailedUnTarKclPackage + return reporter.NewErrorEvent(reporter.FailedCreateFile, err, fmt.Sprintf("failed to open '%s'", tarPath)) } default: return errors.UnknownTarFormat @@ -235,14 +235,14 @@ func DirExists(path string) bool { func CreateSubdirInUserHome(subdir string) (string, error) { homeDir, err := os.UserHomeDir() if err != nil { - return "", errors.InternalBug + return "", reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, failed to load user home directory") } dirPath := filepath.Join(homeDir, subdir) if !DirExists(dirPath) { err = os.MkdirAll(dirPath, 0755) if err != nil { - return "", errors.InternalBug + return "", reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, failed to create directory") } } @@ -255,7 +255,7 @@ func CreateSymlink(oldName, newName string) error { if DirExists(newName) { err := os.Remove(newName) if err != nil { - return errors.InternalBug + return err } } @@ -415,7 +415,7 @@ func CheckPackageSum(checkedSum, localPath string) bool { func AbsTarPath(tarPath string) (string, error) { absTarPath, err := filepath.Abs(tarPath) if err != nil { - return "", errors.InternalBug + return "", err } if filepath.Ext(absTarPath) != ".tar" { diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_path_not_exist/test_suite.stderr b/test/e2e/test_suites/kpm/exec_inside_pkg/add_path_not_exist/test_suite.stderr index e11a9484..c932e15b 100644 --- a/test/e2e/test_suites/kpm/exec_inside_pkg/add_path_not_exist/test_suite.stderr +++ b/test/e2e/test_suites/kpm/exec_inside_pkg/add_path_not_exist/test_suite.stderr @@ -1 +1 @@ -kpm: could not load 'kcl.mod' in '/an_invalid_kcl_pkg'. +kpm: could not load 'kcl.mod' in '/an_invalid_kcl_pkg' diff --git a/test/e2e/test_suites/kpm/exec_outside_pkg/add_exist_not_pkgpath/test_suite.stderr b/test/e2e/test_suites/kpm/exec_outside_pkg/add_exist_not_pkgpath/test_suite.stderr index 97e8e7d7..bb0da759 100644 --- a/test/e2e/test_suites/kpm/exec_outside_pkg/add_exist_not_pkgpath/test_suite.stderr +++ b/test/e2e/test_suites/kpm/exec_outside_pkg/add_exist_not_pkgpath/test_suite.stderr @@ -1,2 +1,2 @@ -kpm: could not load 'kcl.mod' in ''. +kpm: could not load 'kcl.mod' in '' kpm: open /kcl.mod: no such file or directory diff --git a/test/e2e/test_suites/kpm/exec_outside_pkg/add_path_not_exist/test_suite.stderr b/test/e2e/test_suites/kpm/exec_outside_pkg/add_path_not_exist/test_suite.stderr index 97e8e7d7..bb0da759 100644 --- a/test/e2e/test_suites/kpm/exec_outside_pkg/add_path_not_exist/test_suite.stderr +++ b/test/e2e/test_suites/kpm/exec_outside_pkg/add_path_not_exist/test_suite.stderr @@ -1,2 +1,2 @@ -kpm: could not load 'kcl.mod' in ''. +kpm: could not load 'kcl.mod' in '' kpm: open /kcl.mod: no such file or directory diff --git a/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_name_outside/test_suite.stderr b/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_name_outside/test_suite.stderr index 97e8e7d7..bb0da759 100644 --- a/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_name_outside/test_suite.stderr +++ b/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_name_outside/test_suite.stderr @@ -1,2 +1,2 @@ -kpm: could not load 'kcl.mod' in ''. +kpm: could not load 'kcl.mod' in '' kpm: open /kcl.mod: no such file or directory diff --git a/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_name_tag_outside/test_suite.stderr b/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_name_tag_outside/test_suite.stderr index 97e8e7d7..bb0da759 100644 --- a/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_name_tag_outside/test_suite.stderr +++ b/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_name_tag_outside/test_suite.stderr @@ -1,2 +1,2 @@ -kpm: could not load 'kcl.mod' in ''. +kpm: could not load 'kcl.mod' in '' kpm: open /kcl.mod: no such file or directory diff --git a/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_no_args_outside/test_suite.stderr b/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_no_args_outside/test_suite.stderr index 97e8e7d7..bb0da759 100644 --- a/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_no_args_outside/test_suite.stderr +++ b/test/e2e/test_suites/kpm/exec_outside_pkg/add_with_no_args_outside/test_suite.stderr @@ -1,2 +1,2 @@ -kpm: could not load 'kcl.mod' in ''. +kpm: could not load 'kcl.mod' in '' kpm: open /kcl.mod: no such file or directory diff --git a/test/e2e/test_suites/kpm/exec_outside_pkg/login_reg_without_username/test_suite.stderr b/test/e2e/test_suites/kpm/exec_outside_pkg/login_reg_without_username/test_suite.stderr index b9b1ad1b..20fbbf3b 100644 --- a/test/e2e/test_suites/kpm/exec_outside_pkg/login_reg_without_username/test_suite.stderr +++ b/test/e2e/test_suites/kpm/exec_outside_pkg/login_reg_without_username/test_suite.stderr @@ -1 +1,2 @@ -kpm: failed to login, please check registry, username and password is valid. \ No newline at end of file +kpm: failed to login 'ghcr.io', please check registry, username and password is valid +kpm: Get "https://ghcr.io/v2/": unsupported \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/exec_outside_pkg/logout_reg_with_invalid_reg/test_suite.stderr b/test/e2e/test_suites/kpm/exec_outside_pkg/logout_reg_with_invalid_reg/test_suite.stderr index 14bc39df..9f8e38f7 100644 --- a/test/e2e/test_suites/kpm/exec_outside_pkg/logout_reg_with_invalid_reg/test_suite.stderr +++ b/test/e2e/test_suites/kpm/exec_outside_pkg/logout_reg_with_invalid_reg/test_suite.stderr @@ -1 +1,2 @@ -kpm: failed to logout, the registry not logged in. +kpm: failed to logout 'invalid_registry' +kpm: not logged in \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/exec_outside_pkg/run_tar_with_noargs_input/test_suite.stderr b/test/e2e/test_suites/kpm/exec_outside_pkg/run_tar_with_noargs_input/test_suite.stderr index 8a2629fe..3fb98399 100644 --- a/test/e2e/test_suites/kpm/exec_outside_pkg/run_tar_with_noargs_input/test_suite.stderr +++ b/test/e2e/test_suites/kpm/exec_outside_pkg/run_tar_with_noargs_input/test_suite.stderr @@ -1 +1,2 @@ -kpm: failed to load package, please check the package path '' is valid +kpm: could not load 'kcl.mod' in '' +kpm: open /kcl.mod: no such file or directory \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/exec_outside_pkg/run_with_no_args/test_suite.stderr b/test/e2e/test_suites/kpm/exec_outside_pkg/run_with_no_args/test_suite.stderr index 8a2629fe..3fb98399 100644 --- a/test/e2e/test_suites/kpm/exec_outside_pkg/run_with_no_args/test_suite.stderr +++ b/test/e2e/test_suites/kpm/exec_outside_pkg/run_with_no_args/test_suite.stderr @@ -1 +1,2 @@ -kpm: failed to load package, please check the package path '' is valid +kpm: could not load 'kcl.mod' in '' +kpm: open /kcl.mod: no such file or directory \ No newline at end of file