Repository: osbuild/osbuild-composer
Pull request #3140 (2022-11-16 15:44:56)

worker: log failures in ostree resolve job


Patch:
diff --git a/cmd/osbuild-worker/jobimpl-ostree-resolve.go b/cmd/osbuild-worker/jobimpl-ostree-resolve.go
index 8449b3c7f..b77575917 100644
--- a/cmd/osbuild-worker/jobimpl-ostree-resolve.go
+++ b/cmd/osbuild-worker/jobimpl-ostree-resolve.go
@@ -60,6 +60,7 @@ func (impl *OSTreeResolveJobImpl) Run(job worker.Job) error {
 
 		ref, checksum, err := ostree.ResolveParams(reqParams)
 		if err != nil {
+			logWithId.Infof("Resolving ostree params failed: %v", err)
 			setError(err, &result)
 			break
 		}
diff --git a/internal/ostree/ostree.go b/internal/ostree/ostree.go
index e5a7cdfd9..2a6dfd5c9 100644
--- a/internal/ostree/ostree.go
+++ b/internal/ostree/ostree.go
@@ -4,6 +4,7 @@ import (
 	"crypto/tls"
 	"crypto/x509"
 	"encoding/hex"
+	"fmt"
 	"io/ioutil"
 	"net/http"
 	"net/url"
@@ -61,7 +62,7 @@ func VerifyRef(ref string) bool {
 func ResolveRef(location, ref string, consumerCerts bool, subs *rhsm.Subscriptions) (string, error) {
 	u, err := url.Parse(location)
 	if err != nil {
-		return "", NewResolveRefError(err.Error())
+		return "", NewResolveRefError(fmt.Sprintf("error parsing ostree repository location: %v", err))
 	}
 	u.Path = path.Join(u.Path, "refs/heads/", ref)
 
@@ -109,14 +110,14 @@ func ResolveRef(location, ref string, consumerCerts bool, subs *rhsm.Subscriptio
 
 	resp, err := client.Do(req)
 	if err != nil {
-		return "", NewResolveRefError(err.Error())
+		return "", NewResolveRefError(fmt.Sprintf("error sending request to ostree repository %q: %v", u.String(), err))
 	}
 	if resp.StatusCode != http.StatusOK {
 		return "", NewResolveRefError("ostree repository %q returned status: %s", u.String(), resp.Status)
 	}
 	body, err := ioutil.ReadAll(resp.Body)
 	if err != nil {
-		return "", NewResolveRefError(err.Error())
+		return "", NewResolveRefError(fmt.Sprintf("error reading response from ostree repository %q: %v", u.String(), err))
 	}
 	parent := strings.TrimSpace(string(body))
 	// Check that this is at least a hex string.


Test patch:
diff --git a/internal/ostree/ostree_test.go b/internal/ostree/ostree_test.go
index 493bead62..5b7e27474 100644
--- a/internal/ostree/ostree_test.go
+++ b/internal/ostree/ostree_test.go
@@ -85,8 +85,8 @@ func TestOstreeResolveRef(t *testing.T) {
 		}
 
 		errCases := map[input]string{
-			{"not-a-url", "a-bad-ref"}:              "Get \"not-a-url/refs/heads/a-bad-ref\": unsupported protocol scheme \"\"",
-			{"http://0.0.0.0:10/repo", "whatever"}:  "Get \"http://0.0.0.0:10/repo/refs/heads/whatever\": dial tcp 0.0.0.0:10: connect: connection refused",
+			{"not-a-url", "a-bad-ref"}:              "error sending request to ostree repository \"not-a-url/refs/heads/a-bad-ref\": Get \"not-a-url/refs/heads/a-bad-ref\": unsupported protocol scheme \"\"",
+			{"http://0.0.0.0:10/repo", "whatever"}:  "error sending request to ostree repository \"http://0.0.0.0:10/repo/refs/heads/whatever\": Get \"http://0.0.0.0:10/repo/refs/heads/whatever\": dial tcp 0.0.0.0:10: connect: connection refused",
 			{srvConf.Srv.URL, "rhel/8/x86_64/edge"}: fmt.Sprintf("ostree repository \"%s/refs/heads/rhel/8/x86_64/edge\" returned status: 404 Not Found", srvConf.Srv.URL),
 			{srvConf.Srv.URL, "test_forbidden"}:     fmt.Sprintf("ostree repository \"%s/refs/heads/test_forbidden\" returned status: 403 Forbidden", srvConf.Srv.URL),
 			{srvConf.Srv.URL, "get_bad_ref"}:        fmt.Sprintf("ostree repository \"%s/refs/heads/get_bad_ref\" returned invalid reference", srvConf.Srv.URL),
diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go
index 92ce3d342..62c79286c 100644
--- a/internal/weldr/api_test.go
+++ b/internal/weldr/api_test.go
@@ -1141,7 +1141,7 @@ func TestCompose(t *testing.T) {
 			"/api/v1/compose",
 			fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"whatever","parent":"","url":"invalid-url"}}`, test_distro.TestImageTypeOSTree),
 			http.StatusBadRequest,
-			`{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"Get \"invalid-url/refs/heads/whatever\": unsupported protocol scheme \"\""}]}`,
+			`{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"error sending request to ostree repository \"invalid-url/refs/heads/whatever\": Get \"invalid-url/refs/heads/whatever\": unsupported protocol scheme \"\""}]}`,
 			nil,
 			[]string{"build_id"},
 		},