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-22 22:05:57 +0100
commitd2d832f1b621a6bf2bd6fa9294b61e2a9958537e (patch)
tree037dce2a5d77c4d6f60037538bb0df4b24ecb15a
parentf3c18bcdd4fa9d24361b92200e4fb723037c81b0 (diff)
downloadpoky-d2d832f1b621a6bf2bd6fa9294b61e2a9958537e.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. (From OE-Core rev: c78f381a9303ef337aac63e11b16fcdcb29ddbb1) Signed-off-by: Sven Schwermer <sven.schwermer@disruptive-technologies.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-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
16from recipetool.create import RecipeHandler, handle_license_vars 16from recipetool.create import RecipeHandler, handle_license_vars
17from recipetool.create import guess_license, tidy_licenses, fixup_license 17from recipetool.create import guess_license, tidy_licenses, fixup_license
18from recipetool.create import determine_from_url 18from recipetool.create import determine_from_url
19from urllib.error import URLError 19from urllib.error import URLError, HTTPError
20 20
21import bb.utils 21import bb.utils
22import json 22import json
@@ -251,15 +251,18 @@ class GoRecipeHandler(RecipeHandler):
251 req = urllib.request.Request(url) 251 req = urllib.request.Request(url)
252 252
253 try: 253 try:
254 resp = urllib.request.urlopen(req) 254 body = urllib.request.urlopen(req).read()
255 255 except HTTPError as http_err:
256 logger.warning(
257 "Unclean status when fetching page from [%s]: %s", url, str(http_err))
258 body = http_err.fp.read()
256 except URLError as url_err: 259 except URLError as url_err:
257 logger.warning( 260 logger.warning(
258 "Failed to fetch page from [%s]: %s", url, str(url_err)) 261 "Failed to fetch page from [%s]: %s", url, str(url_err))
259 return None 262 return None
260 263
261 parser = GoImportHTMLParser() 264 parser = GoImportHTMLParser()
262 parser.feed(resp.read().decode('utf-8')) 265 parser.feed(body.decode('utf-8'))
263 parser.close() 266 parser.close()
264 267
265 return GoImport(parser.import_prefix, parser.vcs, parser.repourl, None) 268 return GoImport(parser.import_prefix, parser.vcs, parser.repourl, None)