Skip to content
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

Make error messages in update information less vague. #271

Merged
merged 3 commits into from
Apr 14, 2024
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
18 changes: 9 additions & 9 deletions internal/helpers/updateinformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ func NewUpdateInformationFromString(updateinformation string) (UpdateInformation
ui.transportmechanism = parts[0]
if ui.transportmechanism == "zsync" {
if len(parts) < 2 {
return ui, errors.New("Too short")
return ui, errors.New("Update information isn't valid")
}
ui.fileurl = parts[1]
} else if ui.transportmechanism == "gh-releases-zsync" {
if len(parts) < 5 {
return ui, errors.New("Too short")
return ui, errors.New("Update information isn't valid")
}
ui.username = parts[1]
ui.repository = parts[2]
ui.releasename = parts[3]
ui.filename = parts[4]
} else if ui.transportmechanism == "bintray-zsync" {
if len(parts) < 5 {
return ui, errors.New("Too short")
return ui, errors.New("Update information isn't valid")
}
ui.username = parts[1]
ui.repository = parts[2]
ui.packagename = parts[3]
ui.filename = parts[4] // a.k.a. "zsync path"
} else {
return ui, errors.New("This transport mechanism is not yet implemented")
return ui, errors.New("The transport mechanism in update information is not yet implemented")
}
return ui, nil
}
Expand All @@ -89,7 +89,7 @@ func NewUpdateInformationFromString(updateinformation string) (UpdateInformation
func ValidateUpdateInformation(updateinformation string) error {
parts := strings.Split(updateinformation, "|")
if len(parts) < 2 {
return errors.New("Too short")
return errors.New("Update information isn't valid")
}
// Check for allowed transport mechanisms,
// https://github.com/AppImage/AppImageSpec/blob/master/draft.md#update-information
Expand All @@ -101,21 +101,21 @@ func ValidateUpdateInformation(updateinformation string) error {
}
}
if detectedTm == "" {
return errors.New("Invalid transport mechanism")
return errors.New("Invalid transport mechanism in update information")
}

// Currently updateinformation needs to end in "zsync" for all transport mechanisms,
// although this might change in the future
// Note that it is allowable to have something like "some.zsync?foo=bar", which is why we parse it as an URL
u, err := url.Parse(parts[len(parts)-1])
if err != nil {
return errors.New("Cannot parse URL")
return errors.New("Cannot parse URL in update information")
}
if detectedTm == "zsync" && u.Scheme == "" { // FIXME: This apparently never triggers, why?
return errors.New("Scheme is missing, zsync needs e.,g,. http:// or https://")
return errors.New("Scheme is missing in update information, zsync needs e.,g,. http:// or https://")
}
if strings.HasSuffix(u.Path, ".zsync") == false {
return errors.New(updateinformation + " does not end in .zsync")
return errors.New("Update information '" + updateinformation + "' does not end in .zsync")
}

return nil
Expand Down
Loading