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

http.server: handle an empty Json body #2042

Merged
merged 1 commit into from
May 18, 2018

Conversation

wilzbach
Copy link
Member

If req.json is called on an empty Json body, it throws an error message which
is rather hard to understand for the casual observer:

core.exception.AssertError@/usr/include/dlang/dmd/std/typecons.d(2583): Called `get' on null Nullable!Json.
----------------
??:? _d_assert_msg [0xb539aeea]
??:? inout pure nothrow ref @property @nogc @safe inout(vibe.data.json.Json) std.typecons.Nullable!(vibe.data.json.Json).Nullable.get() [0xb5224d99]
??:? ref @property @safe vibe.data.json.Json vibe.http.server.HTTPServerRequest.json() [0xb521431d]
??:? void app.handler(scope vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse) [0xb51e4b4e]
??:? @trusted void vibe.http.server.listenHTTP!(vibe.http.server.HTTPServerSettings).listenHTTP(vibe.http.server.HTTPServerSettings, void function(scope vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)*).__lambda3!(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse).__lambda3(scope vibe.http.server.HTTPServerRequest, scope vibe.http.server.HTTPServerResponse) [0xb51eea3b]
??:? @safe bool vibe.http.server.handleRequest(vibe.internal.interfaceproxy.InterfaceProxy!(vibe.core.stream.Stream).InterfaceProxy, vibe.core.net.TCPConnection, vibe.http.server.HTTPServerContext, ref vibe.http.server.HTTPServerSettings, ref bool, scope stdx.allocator.IAllocator) [0xb5286a8d]
??:? @trusted void vibe.http.server.handleHTTPConnection(vibe.core.net.TCPConnection, vibe.http.server.HTTPServerContext).__lambda4() [0xb5284f46]
??:? @safe void vibe.http.server.handleHTTPConnection(vibe.core.net.TCPConnection, vibe.http.server.HTTPServerContext) [0xb5284c57]
??:? nothrow @safe void vibe.http.server.listenHTTPPlain(vibe.http.server.HTTPServerSettings, void delegate(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse) @safe).doListen(vibe.http.server.HTTPServerContext, bool, bool).__lambda4(vibe.core.net.TCPConnection) [0xb52185a5]
??:? void vibe.core.task.TaskFuncInfo.set!(void delegate(vibe.core.net.TCPConnection) @safe, vibe.core.net.TCPConnection).set(ref void delegate(vibe.core.net.TCPConnection) @safe, ref vibe.core.net.TCPConnection).callDelegate(ref vibe.core.task.TaskFuncInfo) [0xb5351580]
??:? void vibe.core.task.TaskFuncInfo.call() [0xb533184d]
??:? nothrow void vibe.core.task.TaskFiber.run() [0xb5330e65]
??:? void core.thread.Fiber.run() [0xb53e7edb]
??:? fiber_entryPoint [0xb53e7daa]
??:? [0xffffffff]

name "tests"
description "Receive an empty JSON body"
dependency "vibe-d:http" path="../../"
versions "VibeDefaultMain"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove


import std.conv : to;

shared static this()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void main()

assert(false, e.msg);
}
});
}
Copy link
Contributor

@PetarKirov PetarKirov Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And perhaps runEventLoop() before the end of main?

@wilzbach
Copy link
Member Author

(remove VibeDefaultMain)

@s-ludwig s-ludwig merged commit 422a3a3 into vibe-d:master May 18, 2018
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.

3 participants