Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dde-open/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
arg := flag.Arg(0)
var scheme string
u, err := url.Parse(arg)
if err != nil {
if err != nil || u == nil {
Copy link

Choose a reason for hiding this comment

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

suggestion: The u == nil check is redundant for url.Parse and can be removed or replaced with a more meaningful guard.

url.Parse guarantees a non-nil *url.URL whenever err == nil, so u == nil should never be true and just adds noise/misleading signal. If you want to guard against missing/empty args, validate arg (e.g. arg == "") before calling url.Parse, and keep the post-parse check as just if err != nil { ... }.

Suggested implementation:

	arg := flag.Arg(0)
	var scheme string

	if arg == "" {
		gFile := gio.FileNewForCommandlineArg(arg)
		if gFile != nil {
			scheme = gFile.GetUriScheme()
		}
	} else {
		u, err := url.Parse(arg)
		if err != nil {
			gFile := gio.FileNewForCommandlineArg(arg)
			if gFile != nil {
				scheme = gFile.GetUriScheme()
			}
		}
  1. Ensure the corresponding closing braces (}) after this block still match correctly with surrounding code (e.g., where scheme is used later). You may need to add one more } after the snippet if this if block was originally closed later in the function.
  2. If u and err are referenced later in the function, you might need to declare them before the if arg == "" { ... } block (e.g. var u *url.URL; var err error) and assign them inside the else to keep them in scope.

gFile := gio.FileNewForCommandlineArg(arg)
if gFile != nil {
scheme = gFile.GetUriScheme()
Expand Down