summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Schwermer <sven.schwermer@disruptive-technologies.com>2024-04-11 12:10:29 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-04-23 13:33:46 +0100
commit8f2e14ab6562a9a68819a960c66a258ea9dbe246 (patch)
treef2bed6d06e70c8528ae2d10c199b7ef5408fa297
parentc129c47cf9fa119005ea6e3946ebdee0da1db7e0 (diff)
downloadopenembedded-core-8f2e14ab6562a9a68819a960c66a258ea9dbe246.tar.gz
recipetool: Handle unclean response in go resolver
It appears that some go modules repond with a 404 error when trying to resolve them dynamically. The response body may still contain the go-import meta tag. An example for such behaviour is gonum.org/v1/gonum. Signed-off-by: Sven Schwermer <sven.schwermer@disruptive-technologies.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
-rw-r--r--scripts/lib/recipetool/create_go.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/scripts/lib/recipetool/create_go.py b/scripts/lib/recipetool/create_go.py
index c560831442..0fb7115e26 100644
--- a/scripts/lib/recipetool/create_go.py
+++ b/scripts/lib/recipetool/create_go.py
@@ -16,7 +16,7 @@ from html.parser import HTMLParser
from recipetool.create import RecipeHandler, handle_license_vars
from recipetool.create import guess_license, tidy_licenses, fixup_license
from recipetool.create import determine_from_url
-from urllib.error import URLError
+from urllib.error import URLError, HTTPError
import bb.utils
import json
@@ -251,15 +251,18 @@ class GoRecipeHandler(RecipeHandler):
req = urllib.request.Request(url)
try:
- resp = urllib.request.urlopen(req)
-
+ body = urllib.request.urlopen(req).read()
+ except HTTPError as http_err:
+ logger.warning(
+ "Unclean status when fetching page from [%s]: %s", url, str(http_err))
+ body = http_err.fp.read()
except URLError as url_err:
logger.warning(
"Failed to fetch page from [%s]: %s", url, str(url_err))
return None
parser = GoImportHTMLParser()
- parser.feed(resp.read().decode('utf-8'))
+ parser.feed(body.decode('utf-8'))
parser.close()
return GoImport(parser.import_prefix, parser.vcs, parser.repourl, None)