From 3a7de2f9e26322fa1e7f6fd178a72ff36acf0425 Mon Sep 17 00:00:00 2001 From: tizu <60812901+tizu69@users.noreply.github.com> Date: Sat, 21 Dec 2024 18:57:14 +0100 Subject: [PATCH 1/3] Show error in wget on http.get error --- .../data/computercraft/lua/rom/programs/http/wget.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua index 44de78b78e..e7fcec7e2b 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua @@ -45,9 +45,10 @@ local function get(sUrl) write("Connecting to " .. sUrl .. "... ") - local response = http.get(sUrl) + local response, err = http.get(sUrl) if not response then - print("Failed.") + print() -- write() above does not wrap, and error might be longer than available space + print(string.format("Failed: %s", err)) return nil end From 64a4a53b60003de5a7ed5cbcb2846fba32ed12a5 Mon Sep 17 00:00:00 2001 From: tizu <60812901+tizu69@users.noreply.github.com> Date: Sat, 21 Dec 2024 19:03:48 +0100 Subject: [PATCH 2/3] fix: wget error handling print() wraps, I'm braindead I forgot print() wraps :) --- .../resources/data/computercraft/lua/rom/programs/http/wget.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua index e7fcec7e2b..e593d8731b 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua @@ -47,7 +47,6 @@ local function get(sUrl) local response, err = http.get(sUrl) if not response then - print() -- write() above does not wrap, and error might be longer than available space print(string.format("Failed: %s", err)) return nil end From f6061196c8958ef2b9c07ad4463b1033bafd1bbc Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sun, 22 Dec 2024 16:11:13 +0000 Subject: [PATCH 3/3] Use printError(..) to display the message Also fix using the wrong URL in get. This didn't matter in practice, but was a bit confusing. --- .../data/computercraft/lua/rom/programs/http/wget.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua index e593d8731b..917ca9036e 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua @@ -35,7 +35,7 @@ local function getFilename(sUrl) return sUrl:match("/([^/]+)$") end -local function get(sUrl) +local function get(url) -- Check if the URL is valid local ok, err = http.checkURL(url) if not ok then @@ -43,12 +43,12 @@ local function get(sUrl) return end - write("Connecting to " .. sUrl .. "... ") + write("Connecting to " .. url .. "... ") - local response, err = http.get(sUrl) + local response, err = http.get(url) if not response then - print(string.format("Failed: %s", err)) - return nil + printError(err) + return end print("Success.")