diff options
author | bptato <nincsnevem662@gmail.com> | 2023-06-09 15:27:29 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-06-09 15:27:29 +0200 |
commit | e8fa2217df7bacc58e88737f21752bbdf0f5562a (patch) | |
tree | 8fbec22f273f2cab5811b2f9b1dd5ea05496ef1a /src | |
parent | b39e35e46773258cb103397b2372612308c22ae0 (diff) | |
download | chawan-e8fa2217df7bacc58e88737f21752bbdf0f5562a.tar.gz |
Show error messages, fix some fetch crashes
Diffstat (limited to 'src')
-rw-r--r-- | src/bindings/curl.nim | 1 | ||||
-rw-r--r-- | src/display/pager.nim | 5 | ||||
-rw-r--r-- | src/io/loader.nim | 7 | ||||
-rw-r--r-- | src/io/request.nim | 2 |
4 files changed, 14 insertions, 1 deletions
diff --git a/src/bindings/curl.nim b/src/bindings/curl.nim index 169314fd..07395b65 100644 --- a/src/bindings/curl.nim +++ b/src/bindings/curl.nim @@ -298,6 +298,7 @@ proc curl_easy_cleanup*(handle: CURL) proc curl_easy_setopt*(handle: CURL, option: CURLoption): CURLcode {.varargs.} proc curl_easy_perform*(handle: CURL): CURLcode proc curl_easy_getinfo*(handle: CURL, info: CURLINFO): CURLcode {.varargs.} +proc curl_easy_strerror*(errornum: CURLcode): cstring proc curl_mime_init*(handle: CURL): curl_mime proc curl_mime_free*(mime: curl_mime) diff --git a/src/display/pager.nim b/src/display/pager.nim index 0dab3bf0..6db13fac 100644 --- a/src/display/pager.nim +++ b/src/display/pager.nim @@ -15,6 +15,7 @@ import config/config import data/charset import display/term import io/lineedit +import io/loader import io/promise import io/request import io/window @@ -790,7 +791,9 @@ proc handleEvent0(pager: Pager, container: Container, event: ContainerEvent): bo if container.retry.len > 0: pager.gotoURL(newRequest(container.retry.pop()), ctype = container.contenttype) else: - pager.alert("Can't load " & $container.source.location & " (error code " & $container.code & ")") + let errorMessage = getLoaderErrorMessage(container.code) + pager.alert("Can't load " & $container.source.location & " (" & + errorMessage & ")") return false of SUCCESS: if container.replace != nil: diff --git a/src/io/loader.nim b/src/io/loader.nim index 5ed270ca..34eb9b42 100644 --- a/src/io/loader.nim +++ b/src/io/loader.nim @@ -282,6 +282,8 @@ proc onConnected*(loader: FileLoader, fd: int) = loader.ongoing[fd] = response promise.resolve(response) else: + loader.unregisterFun(fd) + loader.unregistered.add(fd) #TODO: reject promise instead. let response = newResponse(res, request) promise.resolve(response) @@ -308,3 +310,8 @@ proc quit*(loader: FileLoader) = let stream = connectSocketStream(loader.process) if stream != nil: stream.swrite(QUIT) + +func getLoaderErrorMessage*(code: int): string = + if code < 0: + return $ConnectErrorCode(code) + return $curl_easy_strerror(CURLcode(cint(code))) diff --git a/src/io/request.nim b/src/io/request.nim index ed38ad47..4a123a0b 100644 --- a/src/io/request.nim +++ b/src/io/request.nim @@ -326,6 +326,8 @@ proc Response_json(ctx: JSContext, this: JSValue, argc: cint, argv: ptr JSValue) return JS_ThrowTypeError(ctx, "Value is not an instance of %s", "Response") let response = cast[Response](op) var s = response.text() + if s == "": + return JS_ThrowSyntaxError("unexpected end of input") return JS_ParseJSON(ctx, addr s[0], cast[csize_t](s.len), cstring"<input>") func credentialsMode*(attribute: CORSAttribute): CredentialsMode = |