Skip to content

Throw an error when a tool has no compatible flavour with the current OS #214

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

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions indexes/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ import (
// DownloadTool downloads and returns the path on the local filesystem of a tool
func DownloadTool(toolRelease *cores.ToolRelease) (*paths.Path, error) {
resource := toolRelease.GetCompatibleFlavour()
if resource == nil {
err := fmt.Errorf("tool %s not available for this OS", toolRelease.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
err := fmt.Errorf("tool %s not available for this OS", toolRelease.String())
err := fmt.Errorf("tool %s not available for this OS/ARCH", toolRelease.String())

logrus.Error(err)
return nil, err
}
installDir := globals.FwUploaderPath.Join(
"tools",
toolRelease.Tool.Name,
Expand Down
22 changes: 22 additions & 0 deletions indexes/download/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,25 @@ func TestDownloadFirmware(t *testing.T) {
require.NotEmpty(t, firmwarePath)
require.FileExists(t, firmwarePath.String())
}

func TestDownloadToolMissingFlavour(t *testing.T) {
toolRelease := &cores.ToolRelease{
Version: semver.ParseRelaxed("1.7.0-arduino3"),
Tool: &cores.Tool{
Name: "bossac",
Package: &cores.Package{
Name: "arduino",
},
},
Flavors: []*cores.Flavor{},
}
defer os.RemoveAll(globals.FwUploaderPath.String())
indexFile := paths.New("testdata/package_index.json")
t.Logf("testing with index: %s", indexFile)
index, e := packageindex.LoadIndexNoSign(indexFile)
require.NoError(t, e)
require.NotEmpty(t, index)
toolDir, err := DownloadTool(toolRelease)
require.Error(t, err)
require.Empty(t, toolDir)
}