The following PoC below will trigger it.
The basic idea is to generate a system-level error by disabling BLE and Wifi in the simulator and making a web-request. Our callback will be called with the wrong number of arguments, generating the error.
This is observed in the beta 1 version of ConnectIQ 3.0.
using Toybox.Application;
using Toybox.Communications;
class ContextBugApp extends Application.AppBase {
function initialize() {
AppBase.initialize();
}
// Trigger bug by setting the following in simulator:
// Wifi: Not Connected
// BLE: Not Connected
//
// Expected Result: responseCode = -104 with `context` passed in
// Actual Result: `Not Enough Arguments Error`
function onResponse(responseCode, data, context) {
System.println("onResponse: " + { "responseCode" => responseCode,
"data" => data,
"context" => context });
}
function onStart(state) {
var url = "jsonplaceholder.typicode.com/.../1";
var parameters = {};
var options = {
:method => Communications.HTTP_REQUEST_METHOD_GET,
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON,
:context => { :foo => "bar" }
};
var responseCallback = method(:onResponse);
Communications.makeWebRequest(url, parameters, options, responseCallback);
}
function onStop(state) {
}
function getInitialView() {
return [ new ContextBugView() ];
}
}
Side-note: Changing the arity of the callback depending on whether a `context` is used seems like a really brittle design due to these kinds of bugs. Seems like it'd be better for an `onResponse` callback to have a fixed specification, something like:
// Unlike canonical spec, `context` is *always* passed in, it's just null if a context wasn't used.
function onResponse(responseCode, data, context) {
if (context == null) {
// Do something
} else {
// Do something else
}
}