loop failing when wrapped in try catch to run few times [closed] - coldfusion

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 10 months ago.
Improve this question
Have this code where i am trying to run a loop for few times to make sure i do get my result, but for some reason, i am still getting an error displayed on sreen and it is not even doing the cflog so i can know what is going on, any help will be appreciated
var aData = [];
for (i = 1; i <= 10; i++) {
try {
var a = {};
var as = calltoapitoogetdata;
a['count'] = as;
ArrayAppend(aData, mData);
var retJSON = serializeJSON(aData);
writedump(retJSON);
//return serializeJSON(aData);
break;
} catch (any e) {
i = i + 1;
cflog(text = "Call failed #i#", application = true, file = "loogevent");
writedump(i);
}
}
Thanks

If your code is still erroring it is most likely coming from the cflog call being made in your cfcatch. If you are running a version of Adobe ColdFusion the script version would be :
WriteLog(type="Error", file="myapp.log", text="[#ex.type#] #ex.message#");
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-t-z/writelog.html
Lucee has made many of the CFScript functions equivalent of their tag names but with Adobe CF there are a number of functions that do not comply with this. <cfdump> -> writeDump for example.

Too long for a comment.
I think troubleshooting is easier if all available information is right in front of you on the screen. So, I would troubleshoot like this. Your code is below with my additions in uppercase:
var aData = [];
for (i = 1; i <= 10; i++) {
try {
WRITEOUTPUT('TRY NUMBER #I# <BR>);
var a = {};
var as = calltoapitoogetdata;
WRITEDUMP(AS);
a['count'] = as;
ArrayAppend(aData, mData);
var retJSON = serializeJSON(aData);
writedump(retJSON);
//return serializeJSON(aData);
break;
} catch (any e) {
i = i + 1; // THIS LINE IS NOT NECESSARY
WRITEOUTPUT('CATCH NUMBER #I# <BR>);
cflog(text = "Call failed #i#", application = true, file = "loogevent"); //THIS LINE GETS REPLACED BY
WRITEDUMP(E);
writedump(i); // THIS LINE GOES AWAY
}
}

Related

IS condition not working in AS3 (extra site wont let me post)

I have a pretty straight forward if statement
var mynum:Number = 0;
var myclip:MovieClip = new thisclass();
addChild(myclip);
in the class file
var i:int = 0;
for (i; i<stage.numChildren; ++i)
{
if (stage.getChildAt(i) is thisclass)
{ trace("true"); }
}
and Im not getting the expected results?
Is there more to the "is" condition?
Solved the issue by using parent instead of stage, not sure why it didn't like stage

Prettier putting if statement on one line

Prettier formats if statement without curley braces into one line.
This means that this :
function getErrorMessage(response) {
let errorMessage = null;
if (!response.originalError.response)
errorMessage = 'network error';
else
errorMessage = response.originalError.response.data.errorMessage;
return errorMessage;
}
becomes this :
function getErrorMessage(response) {
let errorMessage = null;
if (!response.originalError.response) errorMessage = 'network error';
else errorMessage = response.originalError.response.data.errorMessage;
return errorMessage;
}
which is FAR more unreadable.
Is there a way of disabling this?
As asked in a similar question, it turns out that the answer is that you can not and will not be able to.
As for the WFT that an average senses, well... Apparently, opinionated doesn't mean respected and well-considered in opinion of many. It means that it's implementing the author's opinion.
So, surprisingly, the unexpected thing isn't the lack of configurability but rather that there are any options to be set at all! Go figure... Someone should create a new package called EvenPrettier or FexiblyPrettier and fork in more options. If I only knew how, I'd do it.
I finally ended up using Beautify - HookyQR extension for vscode
https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify
Example Settings
File: .jsbeautifyrc
{
"brace_style": "collapse,preserve-inline",
"max_preserve_newlines": 2,
"end_with_newline": false
}
Example Code
File: a.js
function dfs(start) {
if (start > n)
return;
ans.push(start);
for (let i = 0; i <= 9; i++)
dfs(start * 10 + i);
}

Why does this cfscript function work?

I wrote this function, the last line seems wrong* but it actually works. Can someone explain how does this stuff work ?
function convertEncoding(str,from,to) {
var charSetObj = createobject("java", "java.nio.charset.Charset");
var e_to = charsetObj.forName(from);
var e_from = charsetObj.forName(to);
return e_from.decode(e_to.encode(str)).toString();
}
I am on BlueDragon 7 and 7.1JX (not the open source)
I was inspired from this function : http://acoderslife.com/index.cfm/blog/Converting-Text-From-UTF-8-to-ISO-8859-1
* It seems that our last action is to work with the From encoding. It should be From.decode(string) and then To.encode(decoded_string)
The reason it seems off is that you swapped the variable names, so they do not accurately represent the contents:
var e_to = charsetObj.forName(from); // Original encoding
var e_from = charsetObj.forName(to); // New encoding
The reason it works is because the final statement accounts for this by swapping the variables positions, so that despite their names, the code is actually doing this:
return newEncoding.decode( originalEncoding.encode(str) ).toString();
Obviously best to fix the variable names, so you are not scratching your head when you run across this code six months from now.
function convertEncoding(str, from, to) {
var charSetObj = createobject("java", "java.nio.charset.Charset");
var origEncoding = charsetObj.forName( arguments.from );
var newEncoding = charsetObj.forName( arguments.to );
return newEncoding.decode(origEncoding.encode( arguments.str )).toString();
}

Windows Phone 7 Consuming Webservice WSDL

Ok I have written some basic generic webservices before but I have never tried to consume a 3rd party one.
The one I am trying to consume is
http://opendap.co-ops.nos.noaa.gov/axis/webservices/predictions/wsdl/Predictions.wsdl
I am not getting any results back from this what so ever and cannot figure out why.
More odd is it is not even reaching PredictionsClient_getPredictionsAndMetadataCompleted when I put a break point in the code it doesn't even reach it.
Any suggestions would be greatly appreciated
public void Bouy(double meters)
{
PredictionService.Parameters PredictionParams = new PredictionService.Parameters();
PredictionService.PredictionsPortTypeClient PredictionsClient = new PredictionService.PredictionsPortTypeClient();
GeoCoordinateWatcher gc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
//gc.Position.Location.Latitude, gc.Position.Location.Longitude
GeoCoordinate myLocation = new GeoCoordinate(27.931631,-82.802582);
foreach (var bl in BouyLocation.GetAll())
{
GeoCoordinate otherLocation = new GeoCoordinate(bl.Lat, bl.Lon);
PredictionParams.beginDate = DateTime.Now.ToString("yyyyMMdd");
PredictionParams.endDate = DateTime.Now.AddDays(1.0).ToString("yyyyMMdd");
PredictionParams.stationId = bl.LocationID;
PredictionParams.timeZone = 0;
PredictionParams.unit = 1;
PredictionParams.dataInterval = 6;
PredictionsClient.getPredictionsAndMetadataCompleted += new EventHandler<PredictionService.getPredictionsAndMetadataCompletedEventArgs>(PredictionsClient_getPredictionsAndMetadataCompleted);
PredictionsClient.getPredictionsAndMetadataAsync(PredictionParams);
double mymeters = myLocation.GetDistanceTo(otherLocation);
if (mymeters < meters)
{
TextBlock DynTextBlock = new TextBlock
{
Name = "Appearance" + bl.LocationID,
Text = bl.LocationName + PredictionResult,
TextWrapping = System.Windows.TextWrapping.Wrap,
Margin = new Thickness(12, -6, 12, 0),
Style = (Style)Resources["PhoneTextSubtleStyle"]
};
DynamicAppearance.Children.Add(DynTextBlock);
this.nearByLocations.Add(new BouyLocationModel() { LocationName = bl.LocationName, LocationID = bl.LocationID, Lat = bl.Lat, Lon = bl.Lon });
}
}
var test = nearByLocations;
}
void PredictionsClient_getPredictionsAndMetadataCompleted(object sender, PredictionService.getPredictionsAndMetadataCompletedEventArgs e)
{
string err = e.Error.ToString();
PredictionResult = e.Result.ToString();
}
Loooking at the code you have here I think that you have used the importing of a ServiceReference to auto build the classes for you?
Unfortunately I have found that this is rather temperamental on WP7 and the only way I actually got it to work was when I connected it to a Microsoft WCF service. Connecting to anything else just doesn't work.
If you do google searches there are various pages talking about the fact it doesn't work and ways around it (which I couldn't get to work).
However, there are ways around it but it isn't as simple as the auto-generated stuff. Basically you do things manually.
Although there are other ways to manually create the web service what I did was follow the information in the following which worked well: http://zetitle.wordpress.com/2010/10/14/using-reactive-extensions-with-webrequest/
You will need to parse the response yourself but XML to LINQ works really well for this.
Hope that helps, or maybe someone will have the solution as it is something I am interested in knowing how to get working too

Odd ColdFusion Behavior--Abort Not Honored

Using ColdFusion 9.01, occasionally, we have observed an issue where an error may be occurring within a CFC function and when we attempt to add writeDump(foo); and abort; calls to debug the error ColdFusion does not honor those calls.
Example:
private void function index(Event)
{
var rc = Event.getCollection();
var prc = Event.getCollection(private=true);
/** NOT HONORED! **/
writeDump(var=rc);
abort;
prc.JSON = {};
prc.JSON.show = variables.APIProxy.call(
handler = 'shows'
,action = 'read'
,event = arguments.Event
/** THE ERROR IS OCCURING HERE **/
,params = { language=lcase(rc.language.getLanguage_Medium()), show=rc.show_name }
);
prc.JSON.showEpisodes = variables.APIProxy.call(
handler = 'episodes'
,action = 'index'
,event = arguments.Event
,params = { language=lcase(rc.language.getLanguage_Medium()), show=rc.show_name, detail=true }
);
prc.JSON.products = variables.APIProxy.call(
handler = 'products'
,action = 'index'
,event = arguments.Event
,params = { language=lcase(rc.language.getLanguage_Medium()), detail=true }
);
Event.addAssets(
'model/product.js
,model/show.js
,collection/product_mobile.js
,collection/show_mobile.js
,view/product_mobile.js
,view/productList.js
,view/show_mobile.js
,view/showList.js
,model/episode.js
,view/episode_mobile.js
,view/episodeList.js
,collection/episode_mobile.js
,collection/product_mobile.js
,mobile/episodeObject.css
,mobile/show.js
,mobile/show.css
,mobile/category.css
');
Event.setLayout('layout.mobile');
Event.setView("show/index_mobile");
return;
}
I believe we have successfully eliminated caching. I am curious if anyone else has encountered this.
Thank you.
Aaron
I'm guessing that the error is a parse error, not a true runtime error, so it gets thrown before the function actually executes. It's not actually skipping over your abort, it just fails to parse (or execute) the entire thing.
I'm not sure why you're getting a parse error there, but I do know the CF code that handles struct literals is somewhat flaky.
The issue was with the struct literals declared within the argument calls to a function.
i'm going to go out on a limb here and say that your issue might have something to do with this bug:
http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=86960
is there anything in your app that executes in the onRequestEnd() method?
it would be helpful to tell us what exactly is happening and/or the output you're getting when the issue happens.