I seem to be having an issue with the photo uploading function on a site I'm working on.
<cftry>
<cffile
action="upload"
destination="#physicalPath#\PHOTOS"
filefield="photo"
nameconflict="makeunique"
accept="image/jpeg, image/pjpeg"
result="mypicture"
/>
<cfset OutcomeID = "#FORM.OutcomeID#"/>
<!---Inserts file name and outcome id into Uploads table in the database --->
<cfinvoke component="#classpath#.cf_classes.dao.uploads" method="insertPhoto" returnvariable="success">
<cfinvokeargument name="fileName" value="#mypicture.SERVERFILE#"/>
<cfinvokeargument name="OutcomeID" value="#OutcomeID#"/>
</cfinvoke>
<cfset photoError = "Photo uploaded successfully"/>
<cfcatch type="any">
<cfset photoError = "There was an error uploading your photo.<br/> Please make sure it is a JPEG format."/>
</cfcatch>
</cftry>
No matter what, I just keep getting back the error message defined in the cfCatch. What are some good ways to troubleshoot something like this? Do any problems stand out to anyone?
Thanks for the help, I'm still relatively new to CF.
You're masking the exception that your cfcatch is catching by just setting a string in there. If you don't want to remove your exception handler, a quick and easy way to see what the underlying error is while you're still working on the code is to add:
<cfcatch><cfdump var="#cfcatch#"></cfcatch>
You may want to add an abort="true" to your cfcatch to stop processing of further code at that point which can mask your exception dump or cause it not to appear.
Putting cfcatch.message into a string that the user sees is not good practice as this may potentially result in information disclosure which can be a security risk (eg. if the message contains a file path on your server or similar)
Long term, if you're using Coldfusion Builder then you can also use the Coldfusion Debugger that is built in to step through your code and see where it is failing at the state of your variables at that point.
Related
I have built my own simple LMS in ColdFusion. It just uses an iframe to display the course and there is a page that records the tin can statements. It works perfect but I have a course designed in Studio '13/presenter '13, output is tincan, that the resume feature doesn't work on my LMS.
If I use presentation.html, example
https://www.domainname.com/folder/courses/example_course/presentation.html?&actor={"name":["My_Name"],"mbox":["mailto:email#email.com"],"objectType":["Agent"]}&endpoint=https://www.domainname.com/folder/courses/&course_id=5&uuid=9AE6DEA4-9C19-F477-19B9822F1E2F0722®istration=36fc1ee0-2849-4bb9-b697-71cd4cad1b6e&activity_id=https://www.domainname.com/folder/courses/&auth=Basic TG9naW46UGFzc3dvcmQ=
the resume doesn't work but the tincan statements post to my site properly.
If I use presentation_html5.html, example
https://www.domainname.com/folder/courses/example_course/presentation_html5.html?&actor={"name":["My_Name"],"mbox":["mailto:email#email.com"],"objectType":["Agent"]}&endpoint=https://www.domainname.com/folder/courses/&course_id=5&uuid=9AE6DEA4-9C19-F477-19B9822F1E2F0722®istration=36fc1ee0-2849-4bb9-b697-71cd4cad1b6e&activity_id=https://www.domainname.com/folder/courses/&auth=Basic TG9naW46UGFzc3dvcmQ=
the resume does work but the tincan statements don't post.
I've followed the tutorial and setup the resume feature: http://www.articulate.com/support/presenter-09/enabling-and-disabling-the-prompt-to-resume-function
I have tried the course on several different websites on several different server, and in several different browsers (IE 11, FF 34.0.5, Chrome 39.0.2171.95 m), current version of Flash.
The resume function doesn't work.
I have tried the course with all the different options, prompt, etc, flash cookies enable and disabled.
The resume function doesn't work.
I have tried the course on Scorm Cloud. The resume function works!
I have opened presentation.html on my computer in FireFox. The resume function works.
I've narrowed the issue down to TinCan. If I turn TinCan off in the presentation.html file by changing
var g_bTinCan = true; to var g_bTinCan = false;
The course resumes as it should. But since TinCan is off, it doesn't post any statements to my LMS.
I've figured out that I probably need to respond to POST state?method=GET with the state/resume data. So something like this
1Nk30a010904050607080b0on1001811f016110171101811000 (tells the course to go to slide 4 or some thing like that).
I understand the data is encoded/compressed. The data actually comes from the state data posted to the LMS. Each slide posts a resume point. I'm guessing I just need to grab that resume point data from the previous session and post back when the user resumes the course and tincan asks for resume data.
But for some reason, no matter what I return and how I return it. My course just sits there loading. Everything is there, nav bar, course extras, exit button, just the content has the loading sign. Nothing is clickable.
I've tried posting back similar headers that scorm cloud uses in ColdFusion:
Access-Control-Allow-Header: Content-Type,Content-Length,Authorization,If-Match,If-None-Match,X-Experience-API-Version,X-Experience-API-Consistent-Through
Access-Control-Allow-Origin: *
Access-Control-Expose-Header: ETag,Last-Modified,Cache-Control,Content-Type,Content-Length,WWW-Authenticate,X-Experience-API-Version,X-Experience-API-Consistent-Through
Cache-Control: no-cache
Connection: keep-alive
Content-Type: application/json
X-Experience-API-Version: 1.0.0
access-control-allow-methods: HEAD,GET,POST,PUT,DELETE
They come through properly along with the response: 1Nk30a010904050607080b0on1001811f016110171101811000
I've tried the return format as json, plain text, an array. But the course doesn't load. I've also found odd behavior if I refresh then stop the browser immediately (the course never refreshes). It will bring up the resume prompt and then I can click Yes/No. And it works. Obviously that isn't right.
Any ideas? What am I missing? I'm looking for what an Articulate course is expecting as a response from my (or any) LMS/LRS when it asks for a resume point on state?method=GET.
Edit
#Brian: content-type is application/json
LRS should be returning the Content-Type as it was received
This is where it gets tricky. state?method=GET redirects to a cfc function.
../includes/LRSCFC.cfc?method=GetState&returnFormat=plain
This is the function:
<cfheader name="Access-Control-Allow-Header" value="Content-Type,Content-Length,Authorization,If-Match,If-None-Match,X-Experience-API-Version,X-Experience-API-Consistent-Through">
<cfheader name="Access-Control-Allow-Origin" value="*">
<cfheader name="Access-Control-Expose-Header" value="Last-Modified,Cache-Control,Content-Type,Content-Length,WWW-Authenticate,X-Experience-API-Version,X-Experience-API-Consistent-Through">
<cfheader name="Cache-Control" value="no-cache">
<cfheader name="Connection" value="keep-alive">
<cfheader name="Content-Type" value="application/json">
<cfheader name="X-Experience-API-Version" value="1.0.0">
<cfheader name="access-control-allow-methods" value="HEAD,GET,POST,PUT,DELETE">
<cfreturn '1s43040ji1001111a0101101111000'>
The problem is if tell CF to return as json using the function, returnFormat=json, or serializeJSON(). It adds stuff to the returned data.
The above code will return:
1s43040ji1001111a0101101111000
telling CF to use json:
//"1s43040ji1001111a0101101111000"
Which is a secure feature of CF.
But what confuses me is Scorm Cloud just returns
1s43040ji1001111a0101101111000
It isn't formatted like JSON. It just seems like it is plain text even though the Content-Type is application/json.
If I return all the cfheader info but leave cfreturn blank cfreturn "" the course just sits there as if I returned "1s43040ji1001111a0101101111000"
1s43040ji1001111a0101101111000 - Should jump the user to slide 3.
What status code are you returning?
200 OK
Any other status, the course will play but will complain it can't connect to the server.
#Andrew
Any errors, successes, requests in progress?
No errors. Seems like everything is successful. no requests in progress.
I figured out my problem. I was missing Content-Length in the headers. Content-Length is just the length of the response data. So I added this:
<cfheader name="Content-Length" value="#len('1s43040ji1001111a0101101111000')#">
To my current code, like so:
<cfheader name="Access-Control-Allow-Header" value="Content-Type,Content-Length,Authorization,If-Match,If-None-Match,X-Experience-API-Version,X-Experience-API-Consistent-Through">
<cfheader name="Access-Control-Allow-Origin" value="*">
<cfheader name="Access-Control-Expose-Header" value="Last-Modified,Cache-Control,Content-Type,Content-Length,WWW-Authenticate,X-Experience-API-Version,X-Experience-API-Consistent-Through">
<cfheader name="Cache-Control" value="no-cache">
<cfheader name="Connection" value="keep-alive">
<cfheader name="Content-Type" value="application/json">
<cfheader name="X-Experience-API-Version" value="1.0.0">
<cfheader name="access-control-allow-methods" value="HEAD,GET,POST,PUT,DELETE">
<cfheader name="Content-Length" value="#len('1s43040ji1001111a0101101111000')#">
<cfreturn '1s43040ji1001111a0101101111000'>
I'm currently in the process of debugging a ColdFusion system for a client...
Problem is, because they're quite sensitive about any of their systems being screwed up if I were to touch the CF Administrator module, they've made it off limits... And they're quite hesitant to even open it up on a specific IPs because they don't want the stack trace to accidentally be viewed by other users...
So I'm wondering... is there a CF tag or function I can implement in varioous parts of the code to trigger a stack trace in lieu of this access?
If you're trying to get stack traces when errors occur, then you should be able to do that using the onError event on Application.cfc. From there you'll be able to log the exception to a file, send out as an email or hook into something like Hoth or BugLogHG or even 3rd party services like Airbrake or Sentry
// in Application.cfc
function onError(any exception, string event) {
// do something here like send an email / log to file etc
}
If you don't have any errors and you want to get a stack trace then that is harder, but you can fake an error, so something like this might work:
<cfset greeting = "Hello World!">
<cftry>
<!--- deliberately throw an error --->
<cfthrow type="ForceException" message="Thrown Exception">
<cfcatch>
<!---
the cfcatch key has a stacktrace key so you can log/email it
to get the information and the rest of the code will execute
--->
<cflog file="somefile" text="#SerializeJSON(cfcatch)#">
</cfcatch>
</cftry>
<!--- this code will still run --->
<cfoutput>
#greeting#
</cfoutput>
I wrote an application at work that uses a few CFC's- I'm having some errors but I want to actually mail the errors out because the application is live and they are happening rarely.
I can't stop what's currently running to troubleshoot.
Does anyone have any experience/can point me towards doing cfmail inside of a cfc/cfscript? More specifically, inside of a try/catch within cfscript.
We're running ColdFusion 9 which doesn't support <cfmail> inside of <cfscript>.
The mail CFC is built in to CF9 and above. You can use it in cfscript and it shouldn't matter where you implement it - within a try/catch block should be fine in onError.
Adobe has an example of the usage in their documentation for CF9:
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe9cbe5cf462523a0693d5dae123bcd28f6d-7ff9.html
Write a new cfc with a function to send an email and then include that within the try/catch. Something like below will work
sendMail.cfc (missing a lot of things, but this is the structure)
<cfcomponent output="false">
<cffunction name="sendEmail">
<cfargument name="errorMessage">
<cfmail>
<cfdump var="#arguments.errorMessage#">
</cfmail>
</cffunction>
</cfcomponent>
try {
//code here
} catch (any e) {
var sendEmail = new sendMail();
sendEmail.sendEmail(e);
}
I'm having difficulties handling 404 errors correctly in ColdFusion 10 on Windows 2008 R2 x64 using a custom error handler (Execute URL) in IIS. I've done this in previous versions of CF with no problems. In IIS, under the web site features, I open "Error Pages" and set it to execute "/404.cfm" for all 404 errors.
The problem I'm having is that the output of the 404.cfm page is not completely being sent back to the browser and the page doesn't load correctly. Sometimes I get nothing back, other times I get 1K, other times I get a little bit more. It's very inconsistent.
Along with setting the 404.cfm handler in IIS, I am also calling it in the onMissingTemplate() method inside Application.cfm:
<cffunction name="onMissingTemplate"
returnType="boolean"
output="true">
<cfargument name="thePage" type="string" required="true">
<cftry>
<cfmodule template="../../../404.cfm" thePage="#Arguments.thePage#">
<cfcatch>
<cfoutput><p>An error occurred</p></cfoutput>
</cfcatch>
</cftry>
<cfreturn true />
</cffunction>
Inside my 404.cfm error handler, I'm calling:
<cfheader statuscode="404" statustext="Not Found">
... and then I output a bunch of stuff.
When I remove the call to cfheader in 404.cfm, the error handler loads correctly [for ColdFusion requests]. That's because nothing is going through IIS - instead, it's simply going through the onMissingTemplate() method in ColdFusion. However, the response header gives me a 200 status code, which is a problem! It needs to be a 404 status code for obvious reasons.
When I include the cfheader call, OR when a non-ColdFusion page is being requested (IIS will generate the 404 status code), the output of my 404.cfm handler is not completely returned to the browser. I think has something to do with IIS getting its hands on the action.
I did report this in the CF bug database, but I'm wondering if there's something I'm doing wrong. The bug is here: https://bugbase.adobe.com/index.cfm?event=bug&id=3488063
This bug is indeed finally fixed for CF10, with update 11. See http://blogs.coldfusion.com/post.cfm/coldfusion-10-update-11-an-update-with-50-fixes. It only mentions it in passing ("8. Web Container/Tomcat - CGI.server_port, IIS custom error handlers"), but it is there.
And the bug report referenced above has also been updated to indicate that it's fixed with this update.
But let me offer a word of warning: some folks are saying (at the bug report) that they are finding the problem NOT fixed even after applying the update.
There's a very likely explanation: please note that after applying update 11, you MUST either update or rebuild the web connector for IIS. For more on that, see http://blogs.coldfusion.com/post.cfm/coldfusion-10-does-the-connector-need-to-be-re-installed-for-update-11.
More specifically, if you look at the coldfusion10\config\wsconfig[nn\ folder (where nn is a number, of which folders you have more than one), and your isapi_redirect.dll is not dated in May 2013, then you have NOT yet done the needed update 11 and will still seem to have the problem.
And be sure to update all of your connectors, if you have more than one such folder under wsconfig. If after doing that, and restarting IIS perhaps, if you are still having the problem, then do report back at the bug report confirming that. Perhaps there may be something else to explain it, but we'd want to rule this issue out first.
I've updated the bug base bug but will re-iterate my workaround here.
I was able to kludge a fix by wrapping the content of the 404 handler using CFSaveContent then forcibly writing the content length:-
<cfsavecontent variable="thePage">
Your 404 code here
</cfsavecontent>
<cfcontent reset="Yes" type="text/html"><cfheader name="Content-Length" value="#len(thePage)#"><cfoutput>#thePage#</cfoutput><cfabort>
Note: I have the cfcontent through to the cfabort on one line so there's no additional whitespace.
CF9 doesn't seem to set a content length header but it doesn't seem to make a difference.. CF10 however ... Tomcat must not be adding the magic ingredient at the end of the CF handling and passing it back to IIS.
I have not found update 11 to work. Even after connector updates. Another kludgey fix:
<CFPARAM default="0" name="URL.r">
<CFPARAM default="0" name="URL.t">
<CFSET ErrUrl = "/cfm/global/404error.cfm">
<CFIF URL.r IS 0>
<CFIF FindNoCase( ".htm", CGI.HTTP_REFERER ) GT 0>
<CFLOCATION url="#ErrUrl#?r=1&t=htm">
</CFIF>
<CFIF FindNoCase( ".cfm", CGI.HTTP_REFERER ) GT 0>
<CFLOCATION url="#ErrUrl#?r=1&t=cfm">
</CFIF>
<CFLOCATION url="#ErrUrl#?r=1">
</CFIF>
<CFIF URL.t IS "htm">
<CFHEADER statuscode="404" statustext="Page Not Found">
</CFIF>
placed at the top of your error page (change your ErrUrl to point to your error page) works for both CFM and HTM(L) pages. It's gross, but seems to work.
Inside my 404 handler, I added:
<cfheader statuscode="404" statustext="Not Found">
<cfheader name="Connection" value="Close"> <!--- this is the fix! --->
Closing the connection seems to work for some reason.
And to output the page, I'm doing:
<cfcontent reset="Yes" type="text/html">
<cfheader name="Content-Length" value="#Len(fullpage)#">
<cfoutput>#fullpage#</cfoutput>
... where the variable fullpage is the content of the 404 handler.
Now I can now consistently return both a 404 status code error AND the entire contents of my error page. However, when a non-ColdFusion page is requested, the CGI values are not correct. Prior to CF10, I could get the requested page by looking at the CGI parameters, specifically CGI.query_string, which used to look like: “404;http://www.example.com/some/file.html” Now I’m getting: “404;http://www.example.com/jakarta/isapi_redirect.dll”, which makes it impossible to get the requested page.
However, the fact that I can now return an entire document makes this at least a partial workaround to the bug, which is still open (after over a year of CF10 being released)! For now, instead of trying to figure out what page was requested and looking at my sitemap, I'm simply outputting a standard "page not found" error.
I should also mention that I'm using the same 404 handler in the onMissingTemplate method in Application.cfc. The requested page is passed into this method, which I then pass to my 404 handler in the Attribute scope, and I call my 404 handler as a cfmodule. So this is a complete solution when it's a ColdFusion page being requested, and only a partial solution when a non-CF page is requested (since we can't determine the requested file).
fix i came up with after trial and error
is in the custom404.cfm that you have pathed to in iis7
put the following code
<cfinclude template="/inc_mypathtoroot/my404.cfm">
<cfheader name="Connection" value="Close">
then create the file my404.cfm in the root (the path for the include will need to be your include path)
in the my404.cfm file put your processing code.
BUT DO NOT USE <CFABORT> ANYWHERE IN THAT FILE AS IT WILL CAUSE THE CONNECTION TO BE RESET.
I'm extending my errormanagement function which dumps a few scopes of variables and sends them via email to me. I'm using the onError-method in the Application.cfc for this case.
<CFDUMP var="#arguments.exception#" label="Error">
<CFDUMP var="#Application#" label="APPLICATION-Scope" />
<CFDUMP var="#form#" label="FORM-Scope">
<CFDUMP var="#url#" label="URL-Scope">
<CFDUMP var="#CGI#" label="CGI-Scope" />
<CFDUMP var="#session#" label="SESSION-Scope" />
<CFDUMP var="#variables#" label="VARIABLES-Scope" />
the onError has the exception as argument which I dump first in this example.... but how do I get the arguments of the function in which the error occured? For example if I call a UDF in my Application.cfc's onRequest-method like <CFSET giveMeMyScripts("javascript-file-1","javascript-file-2") /> Is this possible to get javascript-file-1 and javascript-file-2? Kind of super-arguments?
Thanks for any thoughts on this.
I'm not 100% sure, but you may be able to just dump arguments. It might depend how many functions deep you are.
Generally if you dump all the scopes and the exception, you have all the bits of information you need.
We do almost exactly what your doing and dump every scope in the application.cfc
Not sure you can do this without setting up a specific error trap inside the function. But if you are simply debugging and need to get past the error, copy the arguments into the request scope temporarily and then dump the request scope.