Skip to content

Return an error when the image URL can't be reached - #116

Merged
esimov merged 1 commit into
esimov:masterfrom
mertkayacs:fix/download-errors
Oct 25, 2026
Merged

esimov merged 1 commit into
esimov:masterfrom
mertkayacs:fix/download-errors

Conversation

@mertkayacs

Copy link
Copy Markdown
Contributor

When the -in URL can't be reached, caire panics:

$ caire -in http://127.0.0.1:9/x.jpg -out out.jpg -preview=false
panic: runtime error: invalid memory address or nil pointer dereference
...
github.com/esimov/caire/utils.DownloadImage(...)
	utils/download.go:19

http.Get returns a nil response along with the error, and the error message reads res.Status. I wrapped the original error instead, so it now prints:

Failed to load the source image: unable to download image file from URI: Get "http://127.0.0.1:9/x.jpg": dial tcp 127.0.0.1:9: connect: connection refused

The test points DownloadImage at a closed httptest server. go vet and the tests pass on Go 1.22 and 1.26 (face detection tests left to CI).

@esimov
esimov merged commit 2bdd244 into esimov:master Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants