Skip to content

Conversation

kooksee
Copy link
Contributor

@kooksee kooksee commented Sep 7, 2025

No description provided.

Signed-off-by: 百里(barry) <kookshine@gmail.com>
Signed-off-by: barry <kooksee@163.com>
Signed-off-by: barry <kookshine@gmail.com>
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @kooksee, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request represents a substantial update focused on improving the foundational aspects of the funk Go module. It introduces a more robust and centralized approach to error handling and logging, streamlines configuration and environment variable management, and provides new command-line utilities for better application control and introspection. The changes also include crucial dependency updates and a Go version bump, ensuring the project remains current and performant.

Highlights

  • Core Library Refactoring: The error handling and assertion mechanisms have undergone a significant overhaul. The assert package now uses an internal must helper, centralizing panic and logging logic. The errors package has been refactored to leverage new interfaces and utility functions moved into a dedicated errinter sub-package, promoting cleaner separation of concerns.
  • Enhanced Configuration and Environment Management: New capabilities for handling configuration and environment variables have been introduced. This includes a new config/envs.go file for defining and loading environment-specific configurations, and an improved env package with explicit reload functionality and support for environment variable prefixes. Custom expression functions can now be registered for use within configuration files.
  • New Utility Packages and CLI Commands: Several new utility packages have been added: cliutils for command-line argument parsing, component/lifecycle for managing application component lifecycles, log/logfields for standardized log field names, log/logutil for common logging helpers, log/impl.slog.go for slog.Handler integration, and syncutil for context-aware function calls. New CLI commands (envcmd, versioncmd, testmain) provide better introspection and management of the application.
  • Dependency Updates and Go Version Bump: The project's Go version has been updated to 1.23.0, and numerous core dependencies, including envsubst, expr, pp, term, machineid, lo, slog-common, testify, and urfave/cli/v3, have been upgraded to their latest versions, ensuring compatibility and leveraging new features.
  • Improved Logging and Debugging: The logging system has been refined with a new slog.Handler implementation, standardized log field names, and enhanced error detail logging. The recovery package now explicitly prints stack traces during panics and exits, aiding in debugging.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several changes across multiple files, primarily focusing on error handling, logging, configuration loading, and code generation. The changes include refactoring error handling with a new errinter package, enhancing logging with zerolog, improving configuration loading with environment variable substitution and patching, and updating code generation for cloud events and enums. The review comments address potential issues related to error handling, logging verbosity, and code clarity.


func RegisterExpr(name string, expr any) {
if registerMap[name] != nil {
panic(fmt.Sprintf("expr:%s has existed", name))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This panic will crash the program. Consider returning an error instead.

os.Exit(1)
}

func Exit1[T any](ret T, err error) T {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This function unconditionally calls os.Exit(1) which will terminate the program. This is a very severe action, and should only be done in exceptional circumstances. Consider if there are alternative error handling strategies that can be used instead, such as returning the error to the caller.

v, err := strconv.ParseBool(dt)
if err != nil {
log.Printf("env: failed to parse string to bool, err=%v\n", err)
slog.Error(fmt.Sprintf("env: failed to parse string to bool, keys=%q value=%s err=%v", names, dt, err))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using slog's structured logging capabilities instead of fmt.Sprintf to improve log readability and searchability.

Suggested change
slog.Error(fmt.Sprintf("env: failed to parse string to bool, keys=%q value=%s err=%v", names, dt, err))
slog.Error("env: failed to parse string to bool", "keys", names, "value", dt, "err", err)

})

configBytes = result.Of(os.ReadFile(cfgPath)).Expect("failed to read config data: %s", cfgPath)
configBytes = cfgFormat(configBytes, &config{workDir: filepath.Dir(cfgPath)})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It seems like cfgFormat is applied before envsubst.Bytes. Should environment variables be substituted before or after the custom format?

if message == "" {
message = err.Error()
} else {
message = fmt.Sprintf("msg:%s err:%s", message, err.Error())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider whether including the original error message in the formatted message is always desirable. It could lead to redundant information in some cases. Perhaps provide an option to control this behavior.

v, err := strconv.ParseFloat(dt, 64)
if err != nil {
log.Printf("env: failed to parse string to float, err=%v\n", err)
slog.Error(fmt.Sprintf("env: failed to parse string to float, keys=%q value=%s err=%v", names, dt, err))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using slog's structured logging capabilities instead of fmt.Sprintf to improve log readability and searchability.

Suggested change
slog.Error(fmt.Sprintf("env: failed to parse string to float, keys=%q value=%s err=%v", names, dt, err))
slog.Error("env: failed to parse string to float", "keys", names, "value", dt, "err", err)

}
}

func AsA[T any](err error) (*T, bool) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider if there is a need for both As and AsA. It seems like they are doing similar things.

Comment on lines +164 to +165
e.Str("error_detail", errDetail(err))
e.Str(zerolog.ErrorFieldName, err.Error())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider if it's necessary to include the error detail in every error log. It could lead to verbose logs in some cases. Perhaps provide an option to control this behavior.

)

func NewSlog(log Logger) slog.Handler {
return &slogImpl{l: log.WithCallerSkip(3)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The skip value of 3 might be too specific. Consider making it configurable or using a more general approach to determine the correct skip value.

Comment on lines 29 to +30

DeviceID = InstanceID

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider generating a unique DeviceID using machineid.ID() instead of defaulting to InstanceID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant