Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add more error test cases for kcl go plugin #338

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/native/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ func TestExecProgramWithPlugin(t *testing.T) {
}
}

func TestExecProgramWithPluginError(t *testing.T) {
client := NewNativeServiceClient()
result, err := client.ExecProgram(&gpyrpc.ExecProgram_Args{
KFilenameList: []string{"main.k"},
KCodeList: []string{code},
})
if err != nil {
t.Fatal(err)
}
if !strings.Contains(result.ErrMessage, "strconv.ParseInt: parsing \"<nil>\": invalid syntax") {
t.Fatal(result.ErrMessage)
}
}

func TestExecArtifactWithPlugin(t *testing.T) {
output := path.Join(t.TempDir(), "example")
client := NewNativeServiceClient()
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestPlugin_strings_panic(t *testing.T) {
t.Skip("cgo disabled")
}
result_json := Invoke("kcl_plugin.strings.panic", []interface{}{"KCL", "KCL", 123}, nil)
if result_json != `{"__kcl_PanicInfo__":true,"message":"[KCL KCL 123]"}` {
if result_json != `{"__kcl_PanicInfo__":"[KCL KCL 123]"}` {
t.Fatal(result_json)
}
}
26 changes: 1 addition & 25 deletions pkg/plugin/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,7 @@ import (
)

type PanicInfo struct {
IsPanic bool `json:"__kcl_PanicInfo__"`

BackTrace []BacktraceFrame `json:"backtrace,omitempty"`
RustFile string `json:"rust_file,omitempty"`
RustLine int `json:"rust_line,omitempty"`
RustCol int `json:"rust_col,omitempty"`

KclPkgPath string `json:"kcl_pkgpath,omitempty"`
KclFile string `json:"kcl_file,omitempty"`
KCLFunc string `json:"kcl_func,omitempty"`
KclLine int `json:"kcl_line,omitempty"`
KclCol int `json:"kcl_col,omitempty"`
KclArgMsg string `json:"kcl_arg_msg,omitempty"`

// only for schema check
KclConfigMetaFile string `json:"kcl_config_meta_file,omitempty"`
KclConfigMetaLine int `json:"kcl_config_meta_line,omitempty"`
KclConfigMetaCol int `json:"kcl_config_meta_col,omitempty"`
KclConfigMetaArgMsg string `json:"kcl_config_meta_arg_msg,omitempty"`

Message string `json:"message"`
ErrTypeCode string `json:"err_type_code,omitempty"`
IsWarning string `json:"is_warning,omitempty"`
Message string `json:"__kcl_PanicInfo__"`
}

type BacktraceFrame struct {
Expand All @@ -45,7 +23,6 @@ func JSONError(err error) string {
}
if err != nil {
x := &PanicInfo{
IsPanic: true,
Message: err.Error(),
}
return x.JSONError()
Expand All @@ -54,7 +31,6 @@ func JSONError(err error) string {
}

func (p *PanicInfo) JSONError() string {
p.IsPanic = true
d, _ := json.Marshal(p)
return string(d)
}
Expand Down
Loading