Shareable Go package experiment in sdk-platform-java by suztomo · Pull Request #3938 · googleapis/sdk-platform-java · GitHub
Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

Shareable Go package experiment in sdk-platform-java#3938

Draft
suztomo wants to merge 1 commit into
mainfrom
shared_go_packages
Draft

Shareable Go package experiment in sdk-platform-java#3938
suztomo wants to merge 1 commit into
mainfrom
shared_go_packages

Conversation

@suztomo

@suztomo suztomo commented Oct 14, 2025

Copy link
Copy Markdown
Member

langaugecontainer and message packages are to be migrated to
the librarian repository.

Thank you for opening a Pull Request! Before submitting your PR, please read our contributing guidelines.

There are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> ☕️

langaugecontainer and message packages are to be migrated to
the librarian repository.
@product-auto-label product-auto-label Bot added the size: m Pull request size is medium. label Oct 14, 2025
@gemini-code-assist

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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 refactors the command-line handling into a shared languagecontainer package, which is a good step towards modularity. However, there are a few critical issues that need to be addressed. The new implementation incorrectly passes os.Args to the Run function, which will cause command dispatching to fail. I've also pointed out that error handling has been changed to use panic, which is not ideal for a CLI tool and should be reverted to graceful error logging and exit codes. Additionally, the --version flag functionality has been lost in the refactoring. My review includes suggestions to fix these issues.

slog.Info("librariangen: finished successfully")
return 0
container := javaContainer{}
os.Exit(languagecontainer.Run(os.Args, &container))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The Run function in languagecontainer expects the command-line arguments without the program name. Currently, os.Args is passed, which includes the program name as the first element (os.Args[0]). This will cause the command dispatching in Run to fail, as it will try to match the program name against commands like generate. You should pass os.Args[1:] instead.

Suggested change
os.Exit(languagecontainer.Run(os.Args, &container))
os.Exit(languagecontainer.Run(os.Args[1:], &container))

Comment on lines +62 to +64
if len(args) < 1 {
panic("args must not be empty")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Panicking on invalid user input (like missing arguments) is ungraceful for a command-line tool. It's better to print an error message and exit with a non-zero status code. This provides a better user experience.

	if len(args) < 1 {
		slog.Error("librariangen: expected a command")
		return 1
	}

Comment on lines +69 to +72
if err != nil {
// TODO: Save it as a response file.
panic(err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Using panic for handling errors from business logic can lead to abrupt program termination, which is generally undesirable for a CLI tool. It's better to log the error and return a non-zero exit code to indicate failure gracefully.

		if err != nil {
			// TODO: Save it as a response file.
			slog.Error("librariangen: generate command failed", "error", err)
			return 1
		}

Comment on lines +77 to +79
if err != nil {
panic(err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Using panic for handling errors can lead to abrupt program termination. It's better to log the error and return a non-zero exit code to indicate failure gracefully, which is more conventional for CLI applications.

		if err != nil {
			slog.Error("librariangen: configure command failed", "error", err)
			return 1
		}

slog.Error("librariangen: unknown command: %s (with flags %v)", args[0], args)
return 1
}
return 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This return 0 statement is unreachable because all paths in the preceding switch statement return a value. This line can be removed.


// run executes the appropriate command based on the CLI's invocation arguments.
// The idiomatic structure is `librariangen [command] [flags]`.
func run(ctx context.Context, args []string) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The removed run function handled the --version flag. This logic has not been moved to the new implementation, which is a regression. The --version flag handling should be added back, likely in the main function before calling languagecontainer.Run.

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@suztomo suztomo changed the title Shareed module experiment in sdk-platform-java Sharable module experiment in sdk-platform-java Oct 14, 2025
@suztomo suztomo changed the title Sharable module experiment in sdk-platform-java Shareable Go package experiment in sdk-platform-java Oct 14, 2025
@suztomo suztomo marked this pull request as draft October 20, 2025 21:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant