shithub: hell

Download patch

ref: 22c76389a787fb39769680882ef5961819429d05
parent: 416dfe4f871a317f87a9e266604d3cad729f9b9b
author: penny <penny@limitedideas.org>
date: Sun Aug 10 20:47:17 EDT 2025

Error handling for downloads and previews

--- a/filehandler.go
+++ b/filehandler.go
@@ -28,7 +28,11 @@
 	args = args[1:]
 
 	_, pathnames, err := downloadPostImages(target)
-
+	
+	if(len(pathnames) == 0) {
+		//We tolerate failing to download some items but if we have none then error out
+		return
+	}
 	for file := range pathnames {
 		defer os.Remove(pathnames[file])
 	}
@@ -62,9 +66,6 @@
 		fmt.Printf("Downloaded: %v\n", download.Name())
 
 	}
-	if err != nil {
-		fmt.Printf("Failed to save images:%v\n", err)
-	}
 	return err
 }
 
@@ -73,7 +74,8 @@
 	for media := range target.MediaAttachments {
 		err, mediafile := downloadImage(target.MediaAttachments[media].URL)
 		if err != nil {
-			fmt.Printf("Media download error:%v\n", err)
+			fmt.Printf("Media download error: %v\n", err)
+			continue
 		}
 		files = append(files, mediafile)
 		pathnames = append(pathnames, mediafile.Name())
@@ -84,8 +86,21 @@
 
 func downloadImage(target string) (err error, file *os.File) {
 	response, err := http.Get(target)
+	if err != nil {
+		return
+	}
+
 	parsedurl, err := url.Parse(target)
+	
+	if err != nil {
+		return
+	}
+
 	filename := path.Base(parsedurl.Path)
+	
+	if err != nil {
+		return
+	}
 
 	file, err = os.CreateTemp("", "*"+filename)
 	if err != nil {
@@ -93,6 +108,7 @@
 	}
 
 	if response.StatusCode != http.StatusOK {
+		fmt.Printf("HTTP Error: %v\n", response.StatusCode)
 		return
 	}
 
--- a/main.go
+++ b/main.go
@@ -220,7 +220,7 @@
 					return
 				}
 				if len(context.Descendants) == 0 {
-					fmt.Printf("\"%v\" has no children")
+					fmt.Printf("\"%v\" has no children\n")
 				}
 				for post := range context.Descendants {
 					saveWorkRef(homeMap, context.Descendants[post], postref)
@@ -233,7 +233,7 @@
 					fmt.Println(err)
 					return
 				}
-
+				hc.pause(true) // pause so user can read the thread
 				for post := range context.Ancestors {
 					saveWorkRef(homeMap, context.Ancestors[post], postref)
 					printPost("?"+postref, context.Ancestors[post])
--