tricorder-observability / Starship

Starship: next-generation Observability platform built with eBPF+WASM
GNU Affero General Public License v3.0
164 stars 25 forks source link

CLI breaks when API Server returns empty response #163

Closed nascentcore-eng closed 1 year ago

nascentcore-eng commented 1 year ago

Describe the bug API Server /api/listModule returns empty response when there is no modules. And CLI will choke on this response, as it expects some fields: image

To Reproduce Deploy Starship Do not create any modules starship-cli module list --api-server=192.168.58.2:30110

Expected behavior Starship CLI should print text to say there is no module created.

Screenshots Provided above

Additional context N/A

gavwu commented 1 year ago

the message show: there is an error when parsing number to a string

I check the code and see the differences between Response.Code and HTTPResp.Code

src/cli/pkg/model/response.go:20

// Response represents the api server response model.
// In order to parse the API server's response and facilitate later formatting of the output
type Response struct {
    Data    []map[string]interface{} `json:"data"`
    Code    string                   `json:"code"`
    Message string                   `json:"message"`
}

src/api-server/http/types.go:61

// Common response type.
type HTTPResp struct {
    // Semantic and usage follow HTTP statues code convention.
    // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
    Code int `json:"code"`

    // A human readable message explain the details of the status.
    Message string `json:"message"`
}

type ListModuleResp struct {
    HTTPResp
    Data []dao.ModuleGORM `json:"data"`
}

should we fix this issue by changing the src/cli/pkg/model/response.go.Response.Code to interface{} or int

the issue is introduced by commit(49bc7b7c0e3cc323aeac95d95c5a51afeed539d7)

oojimmy commented 1 year ago

@gavwu I have fixed this issue, If you have more interest in this project, Please feel free to pick up some issues and submitted a pull request