Skip to content

Fix/new code err with msg#1

Closed
fmyAgi7 wants to merge 3 commits into
aginetwork7:masterfrom
fmyAgi7:fix/NewCodeErrWithMsg
Closed

Fix/new code err with msg#1
fmyAgi7 wants to merge 3 commits into
aginetwork7:masterfrom
fmyAgi7:fix/NewCodeErrWithMsg

Conversation

@fmyAgi7

@fmyAgi7 fmyAgi7 commented Jan 19, 2026

Copy link
Copy Markdown

No description provided.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @fmyAgi7, 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 enhances the error handling system by refining how error messages are formatted for better readability and correctness, and by ensuring that debug output is routed to the appropriate standard error stream. Additionally, it includes a new test to validate these improvements and cleans up an outdated dependency configuration.

Highlights

  • Improved Error Message Formatting: The NewCodeErrWithMsg function now utilizes golang.org/x/text/cases for more accurate and locale-aware title casing of error messages, replacing the less robust strings.ToTitle.
  • Debug Output Redirection: The Debug function has been updated to direct its output to os.Stderr instead of os.Stdout, which is the conventional stream for diagnostic and error information.
  • New Test Case for Error Messages: A new test, TestNewCodeErrWithMsg, has been added to ensure the correct title casing behavior of error messages generated by NewCodeErrWithMsg.
  • Dependency Cleanup: An unnecessary replace directive for github.com/ugorji/go/codec has been removed from the go.mod file, streamlining the project's dependencies.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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.

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

Copy link
Copy Markdown

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 correctly replaces the deprecated strings.ToTitle with cases.Title and redirects debug error output to stderr. The changes are positive and improve the codebase. I've added a couple of comments: one to improve performance by reusing the caser instance, and another to make the new test more robust by properly handling the return value of errors.As to prevent potential panics.

Comment thread errors/z_err_code_test.go
func TestNewCodeErrWithMsg(t *testing.T) {
err1 := errors.NewCodeErrWithMsg(testcodepb.TestErrCodeDbConn, "hello world")
var err2 *errors.ErrCode
t.Log(errors.As(err1, &err2))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The test should check the boolean return value of errors.As instead of just logging it. If errors.As fails, err2 will be nil, and the subsequent call to err2.Error() on the next line will cause a panic, making the test fragile.

if !errors.As(err1, �&err2) {
	t.Fatal("errors.As failed to cast to *errors.ErrCode")
}

Comment thread errors/err_code.go
Comment on lines +50 to +51
caser := cases.Title(language.English)
code.Message = caser.String(strings.TrimSpace(msg))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Creating a caser with cases.Title is a relatively expensive operation. The documentation for golang.org/x/text/cases recommends creating it once and reusing it. To improve performance, consider defining this caser as a package-level variable to avoid creating it on every function call.

@fmyAgi7 fmyAgi7 closed this by deleting the head repository Jan 19, 2026
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.

2 participants