RejectedSoftware Forums

Sign up

requestHTTP error

Hi,

I am currently getting an error when using requestHTTP

function vibe.http.client.requestHTTP (string url, scope void delegate(scope HTTPClientRequest req) requester = null) is not callable using argument types (string, void, void)

It points to the line where the url is at in the requestHTTP function

requestHTTP(callurl,
(scope req) {
},
(scope res){
	if(res.statusCode is 200){
		ExampleTemplate callback =  deserializeJson!ExampleTemplate(parseJsonString(res.bodyReader.readAllUTF8()));
	}
}

);

Any clue to why this is happening? If I am to remove the line where the callback varable is located it compiles without errors.

Re: requestHTTP error

On Fri, 25 Apr 2014 16:17:57 GMT, Darius Clark wrote:

Hi,

I am currently getting an error when using requestHTTP

function vibe.http.client.requestHTTP (string url, scope void delegate(scope HTTPClientRequest req) requester = null) is not callable using argument types (string, void, void)

It points to the line where the url is at in the requestHTTP function

...

Any clue to why this is happening? If I am to remove the line where the callback varable is located it compiles without errors.

Sometimes the error messages are a bit misleading when multiple overloads and anonymous delegates are involved. It could be that there is actually a compile error in the callback = line. One way to test that would be to use a nested function instead and see if the error message changes:

void resHandler(scope HTTPClientResponse res) {
	if(res.statusCode is 200){
		ExampleTemplate callback =  deserializeJson!ExampleTemplate(parseJsonString(res.bodyReader.readAllUTF8()));
	}
}

requestHTTP(callurl,
	(scope req) {
	},
	&resHandler
);

BTW, parseJsonString(res.bodyReader.readAllUTF8()) can also be replaced by res.readJson().

Re: requestHTTP error

On Fri, 25 Apr 2014 17:14:00 GMT, Sönke Ludwig wrote:

On Fri, 25 Apr 2014 16:17:57 GMT, Darius Clark wrote:

Hi,

I am currently getting an error when using requestHTTP

function vibe.http.client.requestHTTP (string url, scope void delegate(scope HTTPClientRequest req) requester = null) is not callable using argument types (string, void, void)

It points to the line where the url is at in the requestHTTP function

...

Any clue to why this is happening? If I am to remove the line where the callback varable is located it compiles without errors.

Sometimes the error messages are a bit misleading when multiple overloads and anonymous delegates are involved. It could be that there is actually a compile error in the callback = line. One way to test that would be to use a nested function instead and see if the error message changes:

void resHandler(scope HTTPClientResponse res) {
	if(res.statusCode is 200){
		ExampleTemplate callback =  deserializeJson!ExampleTemplate(parseJsonString(res.bodyReader.readAllUTF8()));
	}
}

requestHTTP(callurl,
	(scope req) {
	},
	&resHandler
);

BTW, parseJsonString(res.bodyReader.readAllUTF8()) can also be replaced by res.readJson().

Thank you for your answer. Oddly, that did fix that issue but any reason why it would cause that error? I had to kind of recode the way the function work to return the proper information. Also thank you for the tip on on res.readJson(). That made it simple enough. I was looking for something like that but couldnt find it (might not look hard enough).

Re: requestHTTP error

On Fri, 25 Apr 2014 21:18:21 GMT, Darius Clark wrote:

Thank you for your answer. Oddly, that did fix that issue but any reason why it would cause that error? I had to kind of recode the way the function work to return the proper information. Also thank you for the tip on on res.readJson(). That made it simple enough. I was looking for something like that but couldnt find it (might not look hard enough).

I think the reason is that anonymous functions/delegates without explicit parameter types, like the ones used here, are internally rewritten as templates taking any parameter type*. But when the contents of an implicitly instantiated template (by matching parameter types) trigger an error, the error isn't printed, but instead the template instantiation for that specific set of template parameters is marked as a failure and the original error is supressed. This is important for overloading templated functions, but results in weird error messages here. Hope this makes some sense.

Disclaimer: I'm not an expert for details of the DMD implementation, so this may not be an accurate description.

* Thinking about it, instead of a nested function, you could also try to use explicit parameter types in the original code (i.e. (scope HTTPClientResponse res)) and see how that influences the error message.