(JavaScript) Impossible Execution Plan
This example demonstrates what happens when it is not possible to construct an execution plan due to missing dependencies.
The target curl command requires a {{drive_id}} value. However, no variable named drive_id has been defined, and no helper function is registered that can produce it. Although a helper function (getSite) is defined, it only produces site_id, which does not satisfy the requirement.
When ExaminePlan is called, it reports that the execution plan cannot be created because a required input is missing and no function exists to provide it.
When DoYourThing is called, it fails for the same reason. The failure is not due to a network or HTTP error, but because the dependency graph cannot be resolved. The FailReason property indicates this condition with a specific error code.
This example highlights that for an execution plan to be valid, every required input must either:
- Already have a defined value, or
- Be producible by a defined
curl function with resolvable inputs
If neither condition is met, the system correctly detects the unresolved dependency and prevents execution. Note: This example requires Chilkat v11.5.0 or greater. For more information, see https://www.chilkatsoft.com/curl_dependency_engine.asp
var success = false;
success = false;
var httpCurl = new CkHttpCurl();
// This target curl command requires {{drive_id}}.
var targetCurl = "curl -X GET https://graph.microsoft.com/v1.0/drives/{{drive_id}}/root/children";
// Define a helper function that can produce site_id.
// However, it does NOT produce drive_id.
var fnName = "getSite";
httpCurl.AddFunction(fnName,"curl -X GET https://graph.microsoft.com/v1.0/sites/root:/sites/{{site_name}}");
httpCurl.AddOutput(fnName,"id","site_id");
// Provide site_name, so getSite can run.
httpCurl.SetVar("site_name","test");
// Try to examine the execution plan.
// This fails because {{drive_id}} is required by the target curl command,
// but drive_id is not already known and no defined function produces it.
var planJson = new CkJsonObject();
planJson.EmitCompact = false;
success = httpCurl.ExaminePlan(targetCurl,planJson);
if (success == false) {
// Should equal 5.
console.log("ExaminePlan fail reason = " + httpCurl.FailReason);
// Examine the error(s) returned in planJson
console.log(planJson.Emit());
// Expected output:
// {
// "errors": [{
// "variable": "drive_id",
// "msg": "No candidate functions"
// }]
// }
}
// DoYourThing will fail for the same reason.
success = httpCurl.DoYourThing(targetCurl);
// We expect DoYourThing to fail because it is not possible to construct
// a valid execution plan (drive_id cannot be resolved).
if (success == false) {
// FailReason provides a numeric code indicating why the operation failed.
// A value of 5 specifically means that an execution plan could not be created
// due to unresolved dependencies (i.e., a required variable has no source).
console.log("DoYourThing fail reason = " + httpCurl.FailReason);
}
else {
// If execution succeeds, it means the plan was somehow resolved,
// which would be unexpected in this scenario.
console.log("Unexpected success.");
}
|