-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/error #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kooksee
wants to merge
65
commits into
master
Choose a base branch
from
feat/error_id
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Feat/error #46
Changes from all commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
dbcd970
feat(errors): 添加错误接口和日志上下文功能
kooksee d78f7f6
feat(errors): 为错误添加唯一标识符
kooksee dc854bb
feat(errors): 为错误添加错误ID并优化日志记录
kooksee 925c150
refactor(log): 调整导入路径
kooksee e412504
refactor(errors): 优化错误处理逻辑
kooksee cf4960b
feat(errors): 添加错误生成函数 NewErr
kooksee 3a0b94c
feat(result): 添加错误包装函数- 在 Error 类型中添加 WrapErr 方法,用于包装错误并添加标签
kooksee 77bee82
feat(result): 为 Error 类型添加 WithErr 方法
kooksee fa9638d
fix: barry quick fix, 2025-06-27 22:14:36
kooksee 55ff163
refactor(v2): replace aherrcheck with resultchecker
kooksee 6e0ee72
Merge remote-tracking branch 'origin/feat/error_id' into feat/error_id
kooksee 1d4d293
fix(result): remove error wrapping in error handling
kooksee debe88d
refactor(errors): remove unused error ID field
kooksee 8ba16e0
perf(errors): cache error ID in ErrWrap struct
kooksee 5b2abd6
refactor(errors): replace repr with pretty for error formatting
kooksee 2608440
refactor(log): improve error handling and logging
kooksee 8741605
fix: barry quick fix, 2025-06-28 22:14:14
kooksee f70bbef
fix: barry quick fix, 2025-06-28 22:16:21
kooksee f758f62
feat(config): add environment variable configuration support
kooksee 22f33d6
fix: barry quick fix, 2025-07-01 17:35:49
kooksee 957cf56
Merge branch 'feat/error_id' of github.com:pubgo/funk into feat/error_id
kooksee a17c964
fix: barry quick fix, 2025-07-01 17:51:18
kooksee c1e41d3
fix: barry quick fix, 2025-07-02 10:59:56
kooksee 2c40b3e
fix: barry quick fix, 2025-07-04 16:21:34
kooksee df93cb7
fix: barry quick fix, 2025-07-05 16:08:21
kooksee 66fa286
fix: barry quick fix, 2025-07-05 19:51:48
kooksee 94d8c7d
fix: barry quick fix, 2025-07-05 19:55:00
kooksee 9a4ce8b
fix: barry quick fix, 2025-07-05 21:58:05
kooksee e7f9f75
fix: barry quick fix, 2025-07-19 00:08:03
kooksee 2fd0eda
fix: barry quick fix, 2025-07-19 16:59:13
kooksee d7519f9
fix: barry quick fix, 2025-07-19 18:17:36
kooksee 1f400ea
fix: barry quick fix, 2025-07-19 21:26:05
kooksee 22f0d00
fix: barry quick fix, 2025-07-21 21:10:29
kooksee 4389ef3
fix: barry quick fix, 2025-07-22 22:53:43
kooksee b0933a8
fix: barry quick fix, 2025-07-22 22:55:03
kooksee 4eb2a65
fix: barry quick fix, 2025-07-23 23:22:57
kooksee 0f4fae2
fix: barry quick fix, 2025-07-25 21:17:02
kooksee c2b6de1
fix: barry quick fix, 2025-07-25 22:02:30
kooksee 059ce8c
fix: barry quick fix, 2025-07-25 22:07:26
kooksee d5c19c7
fix: barry quick fix, 2025-07-29 23:19:42
kooksee f0bf598
fix: barry quick fix, 2025-07-30 14:18:31
kooksee 59c0949
fix: barry quick fix, 2025-07-30 21:31:06
kooksee 51def87
fix: barry quick fix, 2025-08-11 16:42:02
kooksee a56d0ea
Merge branch 'feat/error_id' of github.com:pubgo/funk into feat/error_id
kooksee 19f9b48
fix: barry quick fix, 2025-08-11 22:48:49
kooksee 6d8d484
fix: barry quick fix, 2025-08-14 14:05:14
kooksee c21d839
fix: barry quick fix, 2025-08-15 15:17:50
kooksee c8dec7d
fix: barry@feat/error_id, 2025-08-16 17:11:28
kooksee c3fbd7e
fix: barry quick fix, 2025-08-19 20:27:49
kooksee 78cea65
Merge branch 'feat/error_id' of github.com:pubgo/funk into feat/error_id
kooksee 7366811
fix: barry@feat/error_id, 2025-08-20 14:16:44
kooksee 149a5cb
Merge branch 'feat/error_id' of github.com:pubgo/funk into feat/error_id
kooksee b0220ea
fix: barry@feat/error_id, 2025-08-20 14:17:55
kooksee 030ef4d
fix: barry@feat/error_id, 2025-08-20 14:18:09
kooksee 065eb0c
fix: barry@feat/error_id, 2025-08-20 18:14:33
kooksee 195d36a
fix: barry quick fix, 2025-08-20 21:05:52
kooksee 2a812f4
fix: barry quick fix, 2025-08-21 22:30:03
kooksee 3f9d1e2
fix: barry quick fix, 2025-08-21 22:32:47
kooksee 4a3d1fb
fix: barry quick fix, 2025-08-21 22:46:21
kooksee 2933d32
fix: barry quick fix, 2025-08-21 23:04:22
kooksee ad46d48
fix: barry@feat/error_id, 2025-08-22 18:05:48
kooksee 34a2b17
fix: barry quick fix, 2025-08-22 20:44:36
kooksee 1cd57fb
fix: barry quick fix, 2025-08-23 23:48:05
kooksee d731cdf
fix: barry quick fix, 2025-08-26 20:44:57
kooksee ffaae77
fix: barry quick fix, 2025-08-26 20:58:19
kooksee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cliutils | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
func IsHelp() bool { | ||
help := strings.TrimSpace(os.Args[len(os.Args)-1]) | ||
if strings.HasSuffix(help, "--help") || strings.HasSuffix(help, "-h") { | ||
return true | ||
} | ||
return false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package envcmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/urfave/cli/v3" | ||
|
||
"github.com/pubgo/funk/config" | ||
"github.com/pubgo/funk/env" | ||
"github.com/pubgo/funk/pretty" | ||
"github.com/pubgo/funk/recovery" | ||
) | ||
|
||
func New() *cli.Command { | ||
return &cli.Command{ | ||
Name: "envs", | ||
Usage: "show all envs", | ||
Action: func(ctx context.Context, command *cli.Command) error { | ||
defer recovery.Exit() | ||
|
||
env.Init() | ||
|
||
fmt.Println("config path:", config.GetConfigPath()) | ||
envs := config.LoadEnvConfigMap(config.GetConfigPath()) | ||
for name, cfg := range envs { | ||
envData := env.Get(name) | ||
if envData != "" { | ||
cfg.Default = envData | ||
} | ||
} | ||
|
||
pretty.Println(envs) | ||
return nil | ||
}, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"sort" | ||
|
||
"github.com/moby/term" | ||
"github.com/pubgo/funk/assert" | ||
"github.com/pubgo/funk/cliutils" | ||
"github.com/pubgo/funk/cmds/versioncmd" | ||
"github.com/pubgo/funk/ctxutil" | ||
"github.com/pubgo/funk/version" | ||
"github.com/urfave/cli/v3" | ||
) | ||
|
||
func main() { | ||
app := &cli.Command{ | ||
Name: "testmain", | ||
Suggest: true, | ||
UseShortOptionHandling: true, | ||
ShellComplete: cli.DefaultAppComplete, | ||
Version: version.Version(), | ||
Commands: []*cli.Command{ | ||
versioncmd.New(), | ||
}, | ||
Before: func(ctx context.Context, command *cli.Command) (context.Context, error) { | ||
if !term.IsTerminal(os.Stdin.Fd()) { | ||
return ctx, fmt.Errorf("stdin is not a terminal") | ||
} | ||
|
||
if cliutils.IsHelp() { | ||
return ctx, cli.ShowAppHelp(command) | ||
} | ||
return ctx, nil | ||
}, | ||
} | ||
|
||
sort.Sort(cli.FlagsByName(app.Flags)) | ||
assert.Exit(app.Run(ctxutil.Signal(), os.Args)) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package versioncmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/urfave/cli/v3" | ||
|
||
"github.com/pubgo/funk/pretty" | ||
"github.com/pubgo/funk/recovery" | ||
"github.com/pubgo/funk/running" | ||
"github.com/pubgo/funk/version" | ||
) | ||
|
||
func New() *cli.Command { | ||
return &cli.Command{ | ||
Name: "version", | ||
Usage: fmt.Sprintf("%s version info", version.Project()), | ||
Commands: []*cli.Command{ | ||
{ | ||
Name: "validate", | ||
Usage: "show version info", | ||
Action: func(ctx context.Context, command *cli.Command) error { | ||
defer recovery.Exit() | ||
running.CheckVersion() | ||
return nil | ||
}, | ||
}, | ||
}, | ||
Action: func(ctx context.Context, command *cli.Command) error { | ||
defer recovery.Exit() | ||
pretty.Println(running.GetSysInfo()) | ||
return nil | ||
}, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package lifecycle | ||
|
||
import "context" | ||
|
||
func WrapNoError(fn func(context.Context)) ExecFunc { | ||
return func(ctx context.Context) error { fn(ctx); return nil } | ||
} | ||
|
||
func WrapNoCtx(fn func() error) ExecFunc { | ||
return func(ctx context.Context) error { return fn() } | ||
} | ||
|
||
func WrapNoCtxErr(fn func()) ExecFunc { | ||
return func(ctx context.Context) error { fn(); return nil } | ||
} | ||
|
||
type ExecFunc = func(context.Context) error | ||
|
||
type Executor struct { | ||
Exec ExecFunc | ||
} | ||
|
||
type Handler func(lc Lifecycle) | ||
|
||
type Lifecycle interface { | ||
AfterStop(f ExecFunc) | ||
BeforeStop(f ExecFunc) | ||
AfterStart(f ExecFunc) | ||
BeforeStart(f ExecFunc) | ||
} | ||
|
||
type Getter interface { | ||
GetAfterStops() []Executor | ||
GetBeforeStops() []Executor | ||
GetAfterStarts() []Executor | ||
GetBeforeStarts() []Executor | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
strings.HasSuffix
can lead to false positives. For example, an argument like--some-option-h
would be incorrectly identified as the-h
help flag. A direct string comparison is safer.Additionally, this implementation is fragile because it only checks the last command-line argument. If a help flag is provided anywhere else in the command, it will not be detected.