Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"index out of bounds, the container is empty" on mac OS when POST endpoint returns empty body #56

Closed
oakes opened this issue Jan 15, 2022 · 1 comment

Comments

@oakes
Copy link

oakes commented Jan 15, 2022

On mac OS, puppy 1.5.0, when a POST endpoint returns an empty body, puppy throws an exception. This was not caught in the unit test because the /post test returns data. If i modify it slightly to return an empty string...

diff --git a/tests/test.nim b/tests/test.nim
index 0794690..9c3a64b 100644
--- a/tests/test.nim
+++ b/tests/test.nim
@@ -111,12 +111,12 @@ try:
       let req = Request(
         url: parseUrl("http://localhost:8080/post"),
         verb: "post",
-        body: "some data"
+        body: ""
       )
       let res = fetch(req)
       doAssert ($req).startsWith("POST http://localhost:8080/post")
       doAssert res.code == 200
-      doAssert res.body == "some data"
+      doAssert res.body == ""

     block:
       # test post + gzip

I get the following:

/Users/sekao/Documents/puppy/tests/test.nim(116) test
/Users/sekao/Documents/puppy/src/puppy.nim(348) fetch
/Users/sekao/.choosenim/toolchains/nim-1.6.2/lib/system/fatal.nim(53) sysFatal
Error: unhandled exception: index out of bounds, the container is empty [IndexDefect]

The error is happening on this line so it looks like it needs to check the string length before trying to copy. This code only runs on mac OS so it wouldn't affect other OSes, but there may be a similar problem elsewhere, i haven't checked.

% nim -v
Nim Compiler Version 1.6.2 [MacOSX: amd64]
Compiled at 2021-12-17
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release
@guzba guzba mentioned this issue Jan 15, 2022
@treeform
Copy link
Owner

Fixed in1.5.1. Feel free to re open if its still an issue.

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

No branches or pull requests

2 participants