From 479033e58c856d5d156699b19ffaebba0562619c Mon Sep 17 00:00:00 2001 From: barry Date: Tue, 9 Dec 2025 19:29:03 +0800 Subject: [PATCH 1/3] chore: quick update fix/releaser at 2025-12-09 20:21:45 --- .github/workflows/lint.yml | 16 ++++++++++------ .github/workflows/release.yml | 25 +++++++++++++++++++++---- .goreleaser.yaml | 4 ++-- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b5b1d921..36b65a9a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,7 +2,7 @@ name: Lint & Test on: push: - branches: [ master ] + branches: [ master ] pull_request: branches: [ master ] @@ -12,14 +12,18 @@ 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') }} @@ -27,7 +31,7 @@ jobs: go-lint-cache-${{ runner.os }}- - name: Go Mod Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cache/go-build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a24fee54..d743e00a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,8 @@ name: Release on: - create: - tags: - - v* + push: + tags: [ "v*.*.*" ] + jobs: release: name: Release on GitHub @@ -10,13 +10,30 @@ jobs: 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 }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 281411d1..f722923d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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: @@ -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: From 32debd2a69770984c63edb709b971bcce91cfbd0 Mon Sep 17 00:00:00 2001 From: barry Date: Tue, 9 Dec 2025 19:29:03 +0800 Subject: [PATCH 2/3] chore: quick update fix/releaser at 2025-12-11 16:26:24 --- .github/workflows/lint.yml | 16 ++++++++++------ .github/workflows/release.yml | 25 +++++++++++++++++++++---- .goreleaser.yaml | 4 ++-- component/cloudevent/client.go | 12 ++++++------ env/env.go | 2 +- result/api.go | 1 + result/error.go | 14 +++++++++++++- result/proxy.go | 4 ++++ result/proxy_test.go | 2 +- result/result.go | 8 ++++++-- result/result_test.go | 4 ++-- 11 files changed, 67 insertions(+), 25 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b5b1d921..36b65a9a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,7 +2,7 @@ name: Lint & Test on: push: - branches: [ master ] + branches: [ master ] pull_request: branches: [ master ] @@ -12,14 +12,18 @@ 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') }} @@ -27,7 +31,7 @@ jobs: go-lint-cache-${{ runner.os }}- - name: Go Mod Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cache/go-build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a24fee54..d743e00a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,8 @@ name: Release on: - create: - tags: - - v* + push: + tags: [ "v*.*.*" ] + jobs: release: name: Release on GitHub @@ -10,13 +10,30 @@ jobs: 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 }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 281411d1..f722923d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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: @@ -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: diff --git a/component/cloudevent/client.go b/component/cloudevent/client.go index cbf9c128..60ad8a8b 100644 --- a/component/cloudevent/client.go +++ b/component/cloudevent/client.go @@ -228,7 +228,7 @@ func (c *Client) doConsumeHandler(streamName, consumerName string, jobSubjects m }). UnwrapOrThrow(&r) if r.IsErr() { - return + return r } // ignore negative delay @@ -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) @@ -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 @@ -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) diff --git a/env/env.go b/env/env.go index 166bac6a..af8230cf 100644 --- a/env/env.go +++ b/env/env.go @@ -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 } diff --git a/result/api.go b/result/api.go index ad65e8f6..a4af1b80 100644 --- a/result/api.go +++ b/result/api.go @@ -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")) diff --git a/result/error.go b/result/error.go index 02397b0a..ddbac152 100644 --- a/result/error.go +++ b/result/error.go @@ -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 @@ -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...) } diff --git a/result/proxy.go b/result/proxy.go index 3c1bb9e6..6fec78d2 100644 --- a/result/proxy.go +++ b/result/proxy.go @@ -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" diff --git a/result/proxy_test.go b/result/proxy_test.go index 389dc650..9e687c04 100644 --- a/result/proxy_test.go +++ b/result/proxy_test.go @@ -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()) diff --git a/result/result.go b/result/result.go index d2344fae..b5582bc8 100644 --- a/result/result.go +++ b/result/result.go @@ -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...) } diff --git a/result/result_test.go b/result/result_test.go index 6e85bf34..00b9be48 100644 --- a/result/result_test.go +++ b/result/result_test.go @@ -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 } @@ -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 } From 24d12ad18a16d4467e53533c05034e4a53f67f32 Mon Sep 17 00:00:00 2001 From: barry Date: Fri, 12 Dec 2025 21:47:46 +0800 Subject: [PATCH 3/3] chore: quick update fix/releaser at 2025-12-12 23:01:41 --- .github/workflows/lint.yml | 2 +- .gitignore | 1 + shutil/shell.go | 7 +++---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 36b65a9a..b37cbfaa 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,7 +2,7 @@ name: Lint & Test on: push: - branches: [ master ] + branches: [ master ] pull_request: branches: [ master ] diff --git a/.gitignore b/.gitignore index 3b749870..5983c431 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ kdata *.pprof *.log proto-vendor +.gitconfig diff --git a/shutil/shell.go b/shutil/shell.go index 1d25ebad..b87a56e0 100644 --- a/shutil/shell.go +++ b/shutil/shell.go @@ -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())) }