Sort invalid versions to the bottom rather than panicking #946

Merged
jade merged 1 commits from jade/abra:handle-sorting-invalid-versions into main 2026-10-14 09:36:01 +00:00
Member

When an app has an invalid version number, it causes a panic. In particular, this causes a panic in the build script to regenerate the recipe catalogue.

For example, see https://build.coopcloud.tech/toolshed/auto-recipes-catalogue-json/2791/1/2

The full error, is:

panic: version show is not supported (matched: ^[a-zA-Z]+$)

goroutine 1 [running]:
coopcloud.tech/abra/pkg/recipe.sortRecipeVersions.func1(0xfbce40?, 0x9)
	/app/pkg/recipe/recipe.go:597 +0x253
sort.insertionSort_func({0xc000309138?, 0xc0073c0d80?}, 0x0, 0xb)
	/usr/local/go/src/sort/zsortfunc.go:12 +0xa7
sort.pdqsort_func({0xc000309138?, 0xc0073c0d80?}, 0xc000309101?, 0xc7d6ba?, 0xc000309110?)
	/usr/local/go/src/sort/zsortfunc.go:73 +0x31a
sort.Slice({0xfbce40, 0xc00000e2d0}, 0xc000309138)
	/usr/local/go/src/sort/slice.go:29 +0x85
coopcloud.tech/abra/pkg/recipe.sortRecipeVersions({0xc00011dc80, 0xb, 0x10})
	/app/pkg/recipe/recipe.go:594 +0x6c
coopcloud.tech/abra/pkg/recipe.Recipe.GetRecipeVersions({{0xc00038c00a, 0x5}, {0x0, 0x0}, {0x0, 0x0}, 0x0, {0xc0147dc040, 0x19}, {0xc008f46450, ...}, ...})
	/app/pkg/recipe/git.go:456 +0x2a7
coopcloud.tech/abra/cli/catalogue.init.func3(0x1bb5540, {0x0, 0x0, 0x0})
	/app/cli/catalogue/catalogue.go:143 +0x485
github.com/spf13/cobra.(*Command).execute(0x1bb5540, {0x1c26720, 0x0, 0x0})
	/app/vendor/github.com/spf13/cobra/command.go:1019 +0x93b
github.com/spf13/cobra.(*Command).ExecuteC(0xc000524608)
	/app/vendor/github.com/spf13/cobra/command.go:1148 +0x3f1
github.com/spf13/cobra.(*Command).Execute(0x1c03aa0?)
	/app/vendor/github.com/spf13/cobra/command.go:1071 +0x13
coopcloud.tech/abra/cli.Run({0x11cf8e8, 0x3}, {0x1314e00, 0x28})
	/app/cli/run.go:312 +0x1015
main.main()
	/app/cmd/abra/main.go:22 +0xa9

This change replaces the panic with ensuring that invalid versions are sorted to the bottom of the list. Unit tests have been added.

This may just move the problem if there are other areas where an invalid version causes a panic. Perhaps in the calling function getRecipeVersions we should filter out invalid ones completely. This seems like a good start for now though.

When an app has an invalid version number, it causes a panic. In particular, this causes a panic in the build script to regenerate the recipe catalogue. For example, see https://build.coopcloud.tech/toolshed/auto-recipes-catalogue-json/2791/1/2 The full error, is: ``` panic: version show is not supported (matched: ^[a-zA-Z]+$) goroutine 1 [running]: coopcloud.tech/abra/pkg/recipe.sortRecipeVersions.func1(0xfbce40?, 0x9) /app/pkg/recipe/recipe.go:597 +0x253 sort.insertionSort_func({0xc000309138?, 0xc0073c0d80?}, 0x0, 0xb) /usr/local/go/src/sort/zsortfunc.go:12 +0xa7 sort.pdqsort_func({0xc000309138?, 0xc0073c0d80?}, 0xc000309101?, 0xc7d6ba?, 0xc000309110?) /usr/local/go/src/sort/zsortfunc.go:73 +0x31a sort.Slice({0xfbce40, 0xc00000e2d0}, 0xc000309138) /usr/local/go/src/sort/slice.go:29 +0x85 coopcloud.tech/abra/pkg/recipe.sortRecipeVersions({0xc00011dc80, 0xb, 0x10}) /app/pkg/recipe/recipe.go:594 +0x6c coopcloud.tech/abra/pkg/recipe.Recipe.GetRecipeVersions({{0xc00038c00a, 0x5}, {0x0, 0x0}, {0x0, 0x0}, 0x0, {0xc0147dc040, 0x19}, {0xc008f46450, ...}, ...}) /app/pkg/recipe/git.go:456 +0x2a7 coopcloud.tech/abra/cli/catalogue.init.func3(0x1bb5540, {0x0, 0x0, 0x0}) /app/cli/catalogue/catalogue.go:143 +0x485 github.com/spf13/cobra.(*Command).execute(0x1bb5540, {0x1c26720, 0x0, 0x0}) /app/vendor/github.com/spf13/cobra/command.go:1019 +0x93b github.com/spf13/cobra.(*Command).ExecuteC(0xc000524608) /app/vendor/github.com/spf13/cobra/command.go:1148 +0x3f1 github.com/spf13/cobra.(*Command).Execute(0x1c03aa0?) /app/vendor/github.com/spf13/cobra/command.go:1071 +0x13 coopcloud.tech/abra/cli.Run({0x11cf8e8, 0x3}, {0x1314e00, 0x28}) /app/cli/run.go:312 +0x1015 main.main() /app/cmd/abra/main.go:22 +0xa9 ``` This change replaces the panic with ensuring that invalid versions are sorted to the bottom of the list. Unit tests have been added. This may just move the problem if there are other areas where an invalid version causes a panic. Perhaps in the calling function `getRecipeVersions` we should filter out invalid ones completely. This seems like a good start for now though.
jade added 1 commit 2026-10-14 06:18:47 +00:00
Sort invalid versions to the bottom rather than panicking
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
e611a3be38
p4u1 approved these changes 2026-10-14 08:14:45 +00:00
p4u1 left a comment
Owner

Thaaanks! Looks good, feel free to merge

Thaaanks! Looks good, feel free to merge
jade merged commit e611a3be38 into main 2026-10-14 09:36:01 +00:00
jade deleted branch handle-sorting-invalid-versions 2026-10-14 09:36:04 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: toolshed/abra#946