Skip to content

Incorrect errList type in Handling Errors section of client_config.md documentation #368

@oka4shi

Description

@oka4shi

Describe the bug
The type of errList is incorrect in the example code in the Handling errors section of docs/client_config.md.

Currently, errList is declared as *gqlerror.List, but errors.As doesn't correctly evaluate this type.
Additionally, the for statement in line 8 got the following error:
cannot range over errList(variable of type *gqlerror.List)

Expected behavior
The correct type of errList should be gqlerror.List, so the code will be like this:

// return both error and field:
resp, err := getUser(...)
return resp.User.Name, err

// handle different errors differently:
resp, err := getUser(...)
- var errList *gqlerror.List
+ var errList gqlerror.List
if errors.As(err, &errList) {
  for _, err := range errList {
    fmt.Printf("%v at %v\n", err.Message, err.Path)
  }
  fmt.Printf("partial response: %v\n", resp)
} else if err != nil {
  fmt.Printf("http/network error: %v\n", err)
} else {
  fmt.Printf("successful response: %v\n", resp)
}

genqlient version
v0.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions