Skip to content
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: 9 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,26 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Create cache directories
run: |
mkdir -p ~/.cache/golangci-lint
mkdir -p ~/.cache/go-build

- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
- uses: actions/setup-go@v5
with:
go-version: 1.22
go-version-file: 'go.mod'

- name: Go Lint Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.cache/golangci-lint/
key: go-lint-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
go-lint-cache-${{ runner.os }}-

- name: Go Mod Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
Expand Down
25 changes: 21 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
name: Release
on:
create:
tags:
- v*
push:
tags: [ "v*.*.*" ]

jobs:
release:
name: Release on GitHub
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create cache directories
run: |
mkdir -p ~/.cache/go-build

- name: Go Mod Cache
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
key: go-mod-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
go-mod-cache-${{ runner.os }}-
go-mod-cache-


- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GITHUB_TOKEN: ${{ secrets.RELEASER_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ kdata
*.pprof
*.log
proto-vendor
.gitconfig
4 changes: 2 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
builds:
- main: ./cmds/protoc-gen-go-errors/main.go
- main: ./cmds/protoc-gen-go-errors2/main.go
id: protoc-gen-go-errors
binary: protoc-gen-go-errors
goos:
Expand All @@ -9,7 +9,7 @@ builds:
goarch:
- amd64
- arm64
- main: ./cmds/protoc-gen-go-enum/main.go
- main: ./cmds/protoc-gen-go-enum2/main.go
id: protoc-gen-go-enum
binary: protoc-gen-go-enum
goos:
Expand Down
12 changes: 6 additions & 6 deletions component/cloudevent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (c *Client) doConsumeHandler(streamName, consumerName string, jobSubjects m
}).
UnwrapOrThrow(&r)
if r.IsErr() {
return
return r
}

// ignore negative delay
Expand All @@ -238,7 +238,7 @@ func (c *Client) doConsumeHandler(streamName, consumerName string, jobSubjects m

r = r.WithErr(msg.NakWithDelay(dur))
if r.IsErr() {
return
return r
}

return r.WithValue(true)
Expand Down Expand Up @@ -399,8 +399,8 @@ func (c *Client) doHandler(meta *jetstream.MsgMetadata, msg jetstream.Msg, job *
"args": string(msg.Data()),
})
})
if err.ThrowErr(&gErr) {
return
if err.Throw(&gErr) {
return gErr
}
args = &pb

Expand All @@ -411,8 +411,8 @@ func (c *Client) doHandler(meta *jetstream.MsgMetadata, msg jetstream.Msg, job *
"args": args,
})
})
if dst.ThrowErr(&gErr) {
return
if dst.Throw(&gErr) {
return gErr
}

ctx = createCtxWithContext(ctx, msgCtx)
Expand Down
2 changes: 1 addition & 1 deletion env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func LoadFiles(files ...string) (r result.Error) {
continue
}

if Set(k, v).ThrowErr(&r) {
if Set(k, v).Throw(&r) {
return r
}

Expand Down
1 change: 1 addition & 0 deletions result/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func Errorf(msg string, args ...any) Error {
return newError(errors.WrapCaller(fmt.Errorf(msg, args...), 1))
}

func ProxyOf(err *error) ProxyErr { return ErrProxyOf(err) }
func ErrProxyOf(err *error) ProxyErr {
if err == nil {
panicIfError(errors.Errorf("err param is nil"))
Expand Down
14 changes: 13 additions & 1 deletion result/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ func (e Error) Err() error { return e.getErr() }

func (e Error) GetErr() error { return e.getErr() }

func (e Error) Unwrap() (void Void) {
if e.IsErr() {
panicIfError(errors.WrapCaller(e.getErr(), 1))
}

return void
}

func (e Error) Must() {
if e.IsOK() {
return
Expand All @@ -160,7 +168,11 @@ func (e Error) Must() {
panicIfError(errors.WrapCaller(e.getErr(), 1))
}

func (e Error) ThrowErr(setter ErrSetter, contexts ...context.Context) bool {
func (e Error) ThrowErr(err *error, contexts ...context.Context) bool {
return catchErr(e, nil, err, contexts...)
}

func (e Error) Throw(setter ErrSetter, contexts ...context.Context) bool {
return catchErr(e, setter, nil, contexts...)
}

Expand Down
4 changes: 4 additions & 0 deletions result/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func (e ProxyErr) GetErr() error {
return lo.FromPtr(e.err)
}

func (e ProxyErr) Err() error {
return lo.FromPtr(e.err)
}

func (e ProxyErr) String() string {
if e.IsOK() {
return "OK"
Expand Down
2 changes: 1 addition & 1 deletion result/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func TestProxy(t *testing.T) {
var gErr error
err := ErrProxyOf(&gErr)
Errorf("test proxy error").Log().ThrowErr(&err)
Errorf("test proxy error").Log().Throw(&err)
assert.NotNil(t, gErr)
assert.NotNil(t, err.GetErr())
assert.Equal(t, gErr, err.GetErr())
Expand Down
8 changes: 6 additions & 2 deletions result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,16 @@ func (r Result[T]) UnwrapOrElse(fn func() T) T {

func (r Result[T]) UnwrapOrEmpty() (t T) {
if r.IsErr() {
return
return t
}
return r.getValue()
}

func (r Result[T]) ThrowErr(setter ErrSetter, contexts ...context.Context) bool {
func (r Result[T]) ThrowErr(err *error, contexts ...context.Context) bool {
return catchErr(ErrOf(r.err), nil, err, contexts...)
}

func (r Result[T]) Throw(setter ErrSetter, contexts ...context.Context) bool {
return catchErr(ErrOf(r.err), setter, nil, contexts...)
}

Expand Down
4 changes: 2 additions & 2 deletions result/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestErrOf(t *testing.T) {
}

func fn1() (r result.Result[string]) {
if fn3().ThrowErr(&r) {
if fn3().Throw(&r) {
return r
}

Expand All @@ -75,7 +75,7 @@ func fn2() (r result.Result[string]) {
IfErr(func(err error) {
log.Err(err).Msg("test error")
}).
ThrowErr(&r)
Throw(&r)
if r.IsErr() {
return r
}
Expand Down
7 changes: 3 additions & 4 deletions shutil/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ func Run(args ...string) (r result.Result[string]) {
cmd := Shell(args...)
cmd.Stdout = b

result.ErrOf(cmd.Run()).
MustWithLog(func(e *zerolog.Event) {
e.Str(logfields.Msg, fmt.Sprintf("failed to execute: %q", args))
})
result.ErrOf(cmd.Run()).Log(func(e *zerolog.Event) {
e.Str(logfields.Msg, fmt.Sprintf("failed to execute: %q", args))
})

return r.WithValue(strings.TrimSpace(b.String()))
}
Expand Down