diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge.go index f0d0c07..31702bf 100644 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge.go +++ b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "regexp" "strings" "mesh-delivery-checker/internal/check" @@ -18,6 +19,9 @@ const ( commitsTool = "gitea.gitea_commits" ) +// notFoundStatus is the 404 of the forge's error, `Gitea API : `. +var notFoundStatus = regexp.MustCompile(`: 404( |$)`) + // forgeReads reads the forge through call (mesh-sdk process.Conn.Call as the checker's own account). type forgeReads struct { call func(key string, body any) (json.RawMessage, error) @@ -33,8 +37,9 @@ func (f forgeReads) File(_ context.Context, repository, path, ref string) (strin owner, repo := ownerRepo(repository) raw, err := f.call(getFileTool, map[string]string{"owner": owner, "repo": repo, "path": path, "ref": ref}) if err != nil { - if strings.Contains(err.Error(), "404") { - // The forge answers 404 for a file the ref does not hold (issue 1845). + if notFoundStatus.MatchString(err.Error()) { + // The forge answers 404 for a file the ref does not hold (issue 1845). The status is matched in its own place, + // after the path's colon: the path carries a sha that may hold the digits 404. return "", fmt.Errorf("%w: %v", check.ErrNotFound, err) } return "", err diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge_test.go index b337053..e7ecc85 100644 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge_test.go +++ b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge_test.go @@ -79,7 +79,9 @@ func TestAFileTheRefDoesNotHoldIsNotFoundAndOtherFailuresAreNot(t *testing.T) { if _, err := f.File(context.Background(), "novox/mesh-catalog", "checks/particulars/go.mod", "98ca97fc"); !errors.Is(err, check.ErrNotFound) { t.Errorf("a 404 is %v, want ErrNotFound", err) } - f = forgeReads{call: func(string, any) (json.RawMessage, error) { return nil, errors.New("Gitea API: 500 internal error") }} + f = forgeReads{call: func(string, any) (json.RawMessage, error) { + return nil, errors.New("Gitea API contents/go.mod?ref=1111111111111111111111111111111404abcde: 500 internal error") + }} if _, err := f.File(context.Background(), "novox/mesh-catalog", "go.mod", "main"); err == nil || errors.Is(err, check.ErrNotFound) { t.Errorf("a 500 is %v, want a failure that is not ErrNotFound", err) }