Skip to content

Commit

Permalink
chore: remove error prefix in the error message
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Nov 22, 2023
1 parent 7868e7e commit 305bcd7
Show file tree
Hide file tree
Showing 33 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion pkg/api/kpm_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestRunPkgInPathInvalidPath(t *testing.T) {
opts.SetPkgPath(filepath.Join(pkgPath, "test_kcl"))
result, err := RunPkgInPath(opts)
assert.NotEqual(t, err, nil)
assert.Equal(t, err.Error(), fmt.Sprintf("error: failed to compile the kcl package\nerror: Cannot find the kcl file, please check the file path %s\n", filepath.Join(pkgPath, "test_kcl", "not_exist.k")))
assert.Equal(t, err.Error(), fmt.Sprintf("failed to compile the kcl package\nCannot find the kcl file, please check the file path %s\n", filepath.Join(pkgPath, "test_kcl", "not_exist.k")))
assert.Equal(t, result, "")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/oci/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ func TestLogin(t *testing.T) {
userPwd := "invalid_password"

err := Login(hostName, userName, userPwd, &settings)
assert.Equal(t, err.Error(), "error: failed to login 'ghcr.io', please check registry, username and password is valid\nerror: Get \"https://ghcr.io/v2/\": denied: denied\n")
assert.Equal(t, err.Error(), "failed to login 'ghcr.io', please check registry, username and password is valid\nGet \"https://ghcr.io/v2/\": denied: denied\n")
}
2 changes: 1 addition & 1 deletion pkg/package/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestValidateKpmHome(t *testing.T) {
oldValue := os.Getenv(env.PKG_PATH)
os.Setenv(env.PKG_PATH, "test_home_path")
err := kclPkg.ValidateKpmHome(os.Getenv(env.PKG_PATH))
assert.Equal(t, err.Error(), "error: environment variable KCL_PKG_PATH cannot be set to the same path as the current KCL package.\n")
assert.Equal(t, err.Error(), "environment variable KCL_PKG_PATH cannot be set to the same path as the current KCL package.\n")
assert.Equal(t, err.Type(), reporter.InvalidKpmHomeInCurrentPkg)
os.Setenv(env.PKG_PATH, oldValue)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ func (e *KpmEvent) Error() string {
result := ""
if e.msg != "" {
// append msg
result = fmt.Sprintf("error: %s\n", e.msg)
result = fmt.Sprintf("%s\n", e.msg)
}
if e.err != nil {
result = fmt.Sprintf("%serror: %s\n", result, e.err.Error())
result = fmt.Sprintf("%s%s\n", result, e.err.Error())
}
return result
}

// Event returns the msg of the event without error message.
func (e *KpmEvent) Event() string {
if e.msg != "" {
return fmt.Sprintf("error: %s\n", e.msg)
return fmt.Sprintf("%s\n", e.msg)
}
return ""
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/semver/semver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func TestLatestVersion(t *testing.T) {
assert.Equal(t, latest, "")

latest, err = LatestVersion([]string{"invalid_version"})
assert.Equal(t, err.Error(), "error: failed to parse version invalid_version\nerror: Malformed version: invalid_version\n")
assert.Equal(t, err.Error(), "failed to parse version invalid_version\nMalformed version: invalid_version\n")
assert.Equal(t, latest, "")

latest, err = LatestVersion([]string{"1.2.3", "1.4.0", "1.3.5", "invalid_version"})
assert.Equal(t, err.Error(), "error: failed to parse version invalid_version\nerror: Malformed version: invalid_version\n")
assert.Equal(t, err.Error(), "failed to parse version invalid_version\nMalformed version: invalid_version\n")
assert.Equal(t, latest, "")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestSettingEnv(t *testing.T) {
assert.Equal(t, settings.DefaultOciRegistry(), "test_reg")
assert.Equal(t, settings.DefaultOciRepo(), "test_repo")
assert.Equal(t, settings.ErrorEvent.Type(), reporter.UnknownEnv)
assert.Equal(t, settings.ErrorEvent.Error(), "error: unknown environment variable 'OCI_REG_PLAIN_HTTP=true'\nerror: invalid environment variable\n")
assert.Equal(t, settings.ErrorEvent.Error(), "unknown environment variable 'OCI_REG_PLAIN_HTTP=true'\ninvalid environment variable\n")
assert.Equal(t, settings.DefaultOciPlainHttp(), false)

err = os.Setenv("OCI_REG_PLAIN_HTTP", "on")
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
error: could not load 'kcl.mod' in '<workspace>/an_invalid_kcl_pkg'
could not load 'kcl.mod' in '<workspace>/an_invalid_kcl_pkg'
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: failed to get package with 'not_exist_tag' from 'localhost:5001/test/k8s'
error: failed to resolve not_exist_tag: localhost:5001/test/k8s:not_exist_tag: not found
failed to get package with 'not_exist_tag' from 'localhost:5001/test/k8s'
failed to resolve not_exist_tag: localhost:5001/test/k8s:not_exist_tag: not found
Original file line number Diff line number Diff line change
@@ -1 +1 @@
error: invalid 'kpm add' argument, you must provide a package name or url for the package
invalid 'kpm add' argument, you must provide a package name or url for the package
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: only support url scheme 'oci://'
error: invalid oci url
only support url scheme 'oci://'
invalid oci url
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: failed to compile the kcl package
error: Cannot find the kcl file, please check the file path
failed to compile the kcl package
Cannot find the kcl file, please check the file path
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: could not load 'kcl.mod' in '<workspace>'
error: open <workspace>/kcl.mod: no such file or directory
could not load 'kcl.mod' in '<workspace>'
open <workspace>/kcl.mod: no such file or directory
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: could not load 'kcl.mod' in '<workspace>'
error: open <workspace>/kcl.mod: no such file or directory
could not load 'kcl.mod' in '<workspace>'
open <workspace>/kcl.mod: no such file or directory
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: could not load 'kcl.mod' in '<workspace>'
error: open <workspace>/kcl.mod: no such file or directory
could not load 'kcl.mod' in '<workspace>'
open <workspace>/kcl.mod: no such file or directory
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: could not load 'kcl.mod' in '<workspace>'
error: open <workspace>/kcl.mod: no such file or directory
could not load 'kcl.mod' in '<workspace>'
open <workspace>/kcl.mod: no such file or directory
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: could not load 'kcl.mod' in '<workspace>'
error: open <workspace>/kcl.mod: no such file or directory
could not load 'kcl.mod' in '<workspace>'
open <workspace>/kcl.mod: no such file or directory
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: oci url or package name must be specified
error: failed to pull kcl package
oci url or package name must be specified
failed to pull kcl package
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: oci url or package name must be specified
error: failed to pull kcl package
oci url or package name must be specified
failed to pull kcl package
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: only support url scheme 'oci://'
error: invalid oci url
only support url scheme 'oci://'
invalid oci url
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: failed to login 'ghcr.io', please check registry, username and password is valid
error: Get "https://ghcr.io/v2/": unsupported
failed to login 'ghcr.io', please check registry, username and password is valid
Get "https://ghcr.io/v2/": unsupported
Original file line number Diff line number Diff line change
@@ -1 +1 @@
error: registry must be specified
registry must be specified
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: failed to logout 'invalid_registry'
error: not logged in
failed to logout 'invalid_registry'
not logged in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
error: registry must be specified
registry must be specified
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: failed to get package with 'invalid_tag' from 'localhost:5001/test/invalid_oci_repo'
error: failed to resolve invalid_tag: localhost:5001/test/invalid_oci_repo:invalid_tag: not found
failed to get package with 'invalid_tag' from 'localhost:5001/test/invalid_oci_repo'
failed to resolve invalid_tag: localhost:5001/test/invalid_oci_repo:invalid_tag: not found
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: repository 'invalid_url/' not found
error: invalid reference: invalid repository
repository 'invalid_url/' not found
invalid reference: invalid repository
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: repository 'invalid_rul/' not found
error: invalid reference: invalid repository
repository 'invalid_rul/' not found
invalid reference: invalid repository
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: could not load 'kcl.mod' in '<workspace>'
error: open <workspace>/kcl.mod: no such file or directory
could not load 'kcl.mod' in '<workspace>'
open <workspace>/kcl.mod: no such file or directory
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: failed to compile the kcl package
error: Cannot find the kcl file, please check the file path
failed to compile the kcl package
Cannot find the kcl file, please check the file path
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: could not load 'kcl.mod' in '<workspace>'
error: open <workspace>/kcl.mod: no such file or directory
could not load 'kcl.mod' in '<workspace>'
open <workspace>/kcl.mod: no such file or directory
Original file line number Diff line number Diff line change
@@ -1 +1 @@
error: oci url must be specified
oci url must be specified
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: only allows one package to be compiled at a time
error: cannot compile multiple packages [<workspace>/test_kpm_run_with_multi_kfile_1 <workspace>/test_kpm_run_with_multi_kfile_1/sub] at the same time
only allows one package to be compiled at a time
cannot compile multiple packages [<workspace>/test_kpm_run_with_multi_kfile_1 <workspace>/test_kpm_run_with_multi_kfile_1/sub] at the same time
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: only allows one package to be compiled at a time
error: cannot compile multiple packages [<workspace>/test_kpm_run_with_multi_pkg/kcl1 <workspace>/test_kpm_run_with_multi_pkg/kcl2] at the same time
only allows one package to be compiled at a time
cannot compile multiple packages [<workspace>/test_kpm_run_with_multi_pkg/kcl1 <workspace>/test_kpm_run_with_multi_pkg/kcl2] at the same time
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: only allows one package to be compiled at a time
error: cannot compile multiple packages [<workspace>/test_kpm_run_with_multi_pkg_1/kcl1 <workspace>/test_kpm_run_with_multi_pkg_1/kcl2 oci://kcl-lang/kcl] at the same time
only allows one package to be compiled at a time
cannot compile multiple packages [<workspace>/test_kpm_run_with_multi_pkg_1/kcl1 <workspace>/test_kpm_run_with_multi_pkg_1/kcl2 oci://kcl-lang/kcl] at the same time

0 comments on commit 305bcd7

Please sign in to comment.