I want create a log file. I tried but its show me an error. Can anyone help? I show my full code here:
http://pastebin.com/SxAMCUnv
Please see this line. I don't know what happened with it, can output error:
<cffile action="WRITE" file="#expandpath('API.log')#"
output="#filecontent#" addnewline="Yes" fixnewline="No"
Edit: I tried and it showed me an error:
Invalid CFML construct found on line 213 at column 110. ColdFusion
was looking at the following text:
''
The CFML compiler was processing:
A cffile tag beginning on line 213, column 2.
The main error is in this line:
<cffile action="WRITE" file="#expandpath('Info.log')#"
output="#filecontent#" addnewline="Yes" fixnewline="No"
Please tell me what's happening?
A superficial glance at your code suggests you're trying to write out a variable fileContent, but at no point do you actually set that variable. Without seeing the error, there;s no way of knowing if that's the problem, or the variable is being created in code that you haven't included.
Another consideration is that you're re-inventing the wheel slightly here. ColdFusion has an inbuilt <cflog> tag or writeLog() statement for writing to log files.
=====
UPDATE (based on updates to the question)
That's a compile error you're getting, and the line that's erroring is not the line you indicated in your code (# pastebin), which is a bit odd. Can you confirm line 213 is that <cffile> line? And can you reproduce that line in its entirety (the snippet you quoted was incomplete). But basically the error message is telling you what's wrong: you have a syntax error in your code. It could be in the specific statement the error message says (line and column), although sometimes depending on the code, the CF compiler can get confused and a syntax error in a preceding line might be reported as being further down the file than it actually is. But for starters, post the whole line of code, not just the first bit of it.
comments tl;dr version -
This answer worked but asker began asking questions about the new error, he was urged to create a new question.
Answer:
I don't see this line in the link you posted (I searched for api.log). Invalid CFML construct typically means you have a syntax error, usually forgetting a closing quote, second pound, or closing your tag (greater than). If the below suggestion doesn't work, look above or below the line containing the cffile for a missing part of a closing pair.
The code you posted:
<cffile action="WRITE" file="#expandpath('API.log')#" output="#filecontent#" addnewline="Yes" fixnewline="No"
...does not have a closing greater than to close your tag. If that is your actual code, I would suspect that is the problem.
<cffile ... >
^^^ this is missing right here
If you're not going to take Adam's suggestion and use cflog (which you should), you also probably want action="append" or you will keep overwriting the file with the contents of fileContent.
==edit==
On a side note, this will not solve your problem but you should be using cfqueryparam, especially when using user entered data.
For example:
Select *
FROM Purchasers
WHERE PurchaserID = #PurchaserID#
Should be
Select *
FROM Purchasers
WHERE PurchaserID = <cfqueryparam cfsqltype="cf_sql_integer" value="#PurchaserID#">
Related
I want create a log file. I tried but its show me an error. Can anyone help? I show my full code here:
http://pastebin.com/SxAMCUnv
Please see this line. I don't know what happened with it, can output error:
<cffile action="WRITE" file="#expandpath('API.log')#"
output="#filecontent#" addnewline="Yes" fixnewline="No"
Edit: I tried and it showed me an error:
Invalid CFML construct found on line 213 at column 110. ColdFusion
was looking at the following text:
''
The CFML compiler was processing:
A cffile tag beginning on line 213, column 2.
The main error is in this line:
<cffile action="WRITE" file="#expandpath('Info.log')#"
output="#filecontent#" addnewline="Yes" fixnewline="No"
Please tell me what's happening?
A superficial glance at your code suggests you're trying to write out a variable fileContent, but at no point do you actually set that variable. Without seeing the error, there;s no way of knowing if that's the problem, or the variable is being created in code that you haven't included.
Another consideration is that you're re-inventing the wheel slightly here. ColdFusion has an inbuilt <cflog> tag or writeLog() statement for writing to log files.
=====
UPDATE (based on updates to the question)
That's a compile error you're getting, and the line that's erroring is not the line you indicated in your code (# pastebin), which is a bit odd. Can you confirm line 213 is that <cffile> line? And can you reproduce that line in its entirety (the snippet you quoted was incomplete). But basically the error message is telling you what's wrong: you have a syntax error in your code. It could be in the specific statement the error message says (line and column), although sometimes depending on the code, the CF compiler can get confused and a syntax error in a preceding line might be reported as being further down the file than it actually is. But for starters, post the whole line of code, not just the first bit of it.
comments tl;dr version -
This answer worked but asker began asking questions about the new error, he was urged to create a new question.
Answer:
I don't see this line in the link you posted (I searched for api.log). Invalid CFML construct typically means you have a syntax error, usually forgetting a closing quote, second pound, or closing your tag (greater than). If the below suggestion doesn't work, look above or below the line containing the cffile for a missing part of a closing pair.
The code you posted:
<cffile action="WRITE" file="#expandpath('API.log')#" output="#filecontent#" addnewline="Yes" fixnewline="No"
...does not have a closing greater than to close your tag. If that is your actual code, I would suspect that is the problem.
<cffile ... >
^^^ this is missing right here
If you're not going to take Adam's suggestion and use cflog (which you should), you also probably want action="append" or you will keep overwriting the file with the contents of fileContent.
==edit==
On a side note, this will not solve your problem but you should be using cfqueryparam, especially when using user entered data.
For example:
Select *
FROM Purchasers
WHERE PurchaserID = #PurchaserID#
Should be
Select *
FROM Purchasers
WHERE PurchaserID = <cfqueryparam cfsqltype="cf_sql_integer" value="#PurchaserID#">
After my form submits I am calling a controller method that runs an orm EntitySave in my cfc. I would like to dump out the arguments before I save my data via ORM just to visually validate those are indeed the values I want to save in the database.
So when I use this
<cfthrow message="value = #arguments#">
I am getting this:
Error: Complex object types cannot be converted to simple values.
I understand you are not allowed to do this with complex objects, so in those cases I would use <cfdump> but I can't find a way to dump in a <cfthrow>. I am sure there is a better way to accomplish this. I have also tried doing a <cfmail> to myself which works amazingly but the email will take a minute or two. Any suggestions would be greatly appreciated. I am currently checking into ValidateThis.
You could serialise it:
<cfthrow message="value = #serializeJson(arguments)#">
But I don't think you want that sort of thing showing up on the screen.
I'd log it if I was you (so same notion, just <cflog> before the <cfthrow>, and put the arguments in the log entry, and in the <cfthrow> just put a brief explanation of the error (you should also use a TYPE attribute, for subsequent handling of the exception that you've raised.
Rather than throwing it, you could try dumping it to a file and see if that meets your needs:
<cfdump var="#arguments#" output="C:\dump.html" format="html">
If you need to abort (as a throw would do), you can add abort on to the end of the tag, <cfdump... abort>.
You could do the following in order to use <cfdump>:
<cfsavecontent variable="arguments_dump">
<cfdump var="#arguments#" />
</cfsavecontent>
<cfthrow message="#arguments_dump#" />
Takes a little bit more code however and is not as elegant as Adam Cameron's answer above.
Here's a weird one. I haven't had any luck finding any information about this on Google, so I'm wondering if any of you have seen this before?
I've got a CFC in the request scope and then in the onRequestEnd event I grab that CFC out of the request scope and do some end-of-request stuff with it. The problem is I can't reference the variable in my onRequestEnd event because it produces an error that says it's not defined in the scope... but here's where it gets really weird and why I KNOW this is a bug (it's not just a suspicion)... If I DUMP the variable, the cfdump tag successfully displays the CFC and all its stuff... and then produces the same "is undefined in scope" error. Here's a screen-capture.
So... anybody seen this before? 'Cause I'm totally stumped. I've already installed the 9.0.1 updater and both of the cumulative hot fixes.
p.s. Yeah, I know it says OnRequestEnd.cfm, but this is actually inside the Application.cfc onRequestEnd method -- it's a legacy from the framework dating back originally to CF5, just go with it. ;P
EDIT: Okay, it's gotten weirder... I tried using evaluate() to set it to a local variable, which apparently works, because then I dump the local variable. The dump still works, even though it's on line 2 AFTER the line on which the error occurred?!!
EDIT 2: EDIT: Here's the code from the Application.cfc that includes the file where the error occurs:
<cffunction name="onRequestEnd" access="public" output="true">
<cfinclude template="OnRequestEnd.cfm">
</cffunction>
It appears to have something to do with the combination of the method and the include file.
It still fails if I execute the method in the onRequestStart like this:
<cffunction name="onRequestStart" access="public" output="true">
<cfset onRequestEnd() />
</cffunction>
But it works fine if I include the file in onRequestStart like this.
<cffunction name="onRequestStart" access="public" output="true">
<cfinclude template="OnRequestEnd.cfm">
</cffunction>
HOWEVER! There's obviously more to this because I can't create a simple test case. If I create a new project with a very simple application.cfc in it and replicate all these details, it works fine. So there's something else in the framework that's contributing to it beyond just the method names and file names.
And the file name doesn't seem to actually contribute, since it still fails in the same way if I change the name of the file like this:
<cffunction name="onRequestEnd" access="public" output="true">
<cfinclude template="reqend.cfm">
</cffunction>
EDIT 3: Okay it has nothing to do with the file... well it does, but not with the file name... At the bottom of the onRequestEnd.cfm is this code
<!--- this seems to help resolve a leaky-memory issue in CF/JRun --->
<cfset structClear(variables) />
<cfset structClear(request) />
<cfabort />
If I comment out those StructClear statements, then the error goes away, which told me that it was executing the OnRequestEnd.cfm twice... and I THINK that means that CF9 changed the behavior of the CFABORT tag and it now executes the onRequestEnd event when the tag is used... it didn't in previous versions of cf...
I didn't find documentation of this, but I did find this blog from Ben Nadel about this behavior with the CFLOCATION tag, so it seems to be more generally about the onRequestEnd event. It seems now in CF9, no matter how a page finishes executing, the onRequestEnd event is executed at the end... That's a change from all the previous versions and so it mucks with code I had created in order to actually cause this to happen on previous versions. Since I was causing execution of the onRequestEnd and then aborting the page early, CF now executes the onRequestEnd, aborts and then executes the onRequestEnd again because of the abort.
Luckily, this fairly simple bit of code at the top of the template seems to fix the problem:
<cfif structIsEmpty(request)>
<cfexit method="exittemplate" />
</cfif>
I decided to leave this question here (rather than deleting it) since it may help some other folks, though I found the source of the problem and a workaround while working with some of the comments and it wasn't what we thought. Ben Nadel also posted a blog about the change to CFABORT a while ago as well... and Adam Cameron tells me that although this change was added by-design in CF9 (without warning anyone apparently, since I saw no mention in the LiveDocs and added 2 comments about it), it was then removed in the (not yet released?) CF10. I think Adam might be in the beta, I'm not sure.
This code:
<cfimage action="info" structName="imageInfo" source="#imagePath#">
is giving this error:
The attribute 'structName' is required for the tag. (Found:
[source, structname, action])
When I run this code in CFBuilder - everything is OK, but I must use CFEclipse.
What should I do (I use CF9)?
Thank you for your answers!
Of course this problem won't prevent you from running your application on ColdFusion. It is just an IDE warning that something is wrong.
You have a few options.
Try using a lowercase N in structName. i.e. structname. ColdFusion is not case-sensitive, but Java is, and CFEclipse is a Java application.
If that does not work, then it probably means that the dictionary file that drives the code assist is not correct. You can go earch forthose XML files and update them to include that attribute.
You can use CFBuilder. I know you said you can't, but I have to question why. You know there is a free version that is just as good as CFEclipse, right?
The problem is that there's a casing glitch in that file Peter mentions. There's one reference to "structName" to define the attribute itself, and another "structname" which is in the list defining which attributes are needed for action="info". If you make them both the same, then restart Eclipse, you should be OK (that's I've needed to do to make the error indicator go away).
I cannot find a function that tells me the attributes of a given file. I specifically need to get the file's size. How do I find this info.?
edit:
I think I found an answer, just not the answer I was hoping for:
So far till ColdFusion 7, there was no
good way to find information like
size, last modified date etc about a
file. Only way you could do that was
to use cfdirectory tag to list the
directory, get the query from it, loop
over the query until you hit the
desired file and then fetch the
required metadata.
http://coldfused.blogspot.com/2007/07/new-file-io-in-coldfusion-8-part-ii.html
Anyone know of a better way?
I believe cfdirectory is your simplest answer - but note, you can use the filter attribute as your filename, and you won't have to loop over the result.
<cffunction name="getFileSize">
<cfargument name="filepath">
<cfreturn createObject("java","java.io.File").init(Arguments.filepath).length()>
</cffunction>
The CFLib FileSysLibrary has a bunch of file functions.
FileSize
FileSizeCOM
May be of particular interest