Wrap a common "cast error" for To___E functions
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 4k
- Forks
- 337
- Avg merge
- 15m
- Merged PRs (30d)
- 1
Description
To make it easier to use Go1.13's errors.Is and errors.As, it'd be great if the To___E functions wrap a common "cast error" so that transitive callers to these functions can determine if an error comes from casting.
A slightly-silly example usecase:
func main() {
val, err := maybeCast("not_an_int")
if errors.Is(err, cast.Err) {
fmt.Println("unable to cast!")
}
fmt.Println(val)
}
func maybeCast(myVal string) (int, error) {
if someCondition() {
return cast.ToIntE(myVal)
}
return fmt.Errorf("unrelated error")
}
If there's interest, I'd love to make a PR. :)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the To___E functions and reviewing how their errors are currently produced. Check Go 1.13 errors.Is and errors.As behavior, then define the shared cast-error behavior and verify that callers can identify casting failures without matching individual messages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100