StackOverflow error when using ORM inside a transaction - coldfusion

If I put any sort of ORM operations inside a transaction, I get an error.
Setup: CentOS 6, MySQL 5.6 and Lucee 4.5.1.
Code
<!--- stuff here is fine --->
<cftransaction>
<cfscript>
qryInsert = EntityNew("Game");
<cfscript>
</cftransaction>
or
<cfscript>
//stuff here is fine...
transaction{
qryInsert = EntityNew("Game");
}
</cfscript>
Entities
League.cfc
component persistent="true" table="Leagues"{
property name="leagueID" ormtype="int" fieldtype="id" generator="identity";
property name="User" fieldtype="many-to-one" cfc="User" fkcolumn="userID";
property name="LeagueTournamentType" fieldtype="many-to-one" cfc="LeagueTournamentType" fkcolumn="leagueTournamentTypeID";
property name="leagueName" ormtype="string";
property name="leagueAbbr" ormtype="string";
property name="teamName" ormtype="string";
property name="gameInMinutes" ormtype="int";
property name="deleteYN" ormtype="boolean";
property name="showReportYN ormtype="boolean";
}
Season.cfc
component persistent="true" table="Seasons"{
property name="seasonID" ormtype="int" fieldtype="id" generator="identity";
property name="User" fieldtype="many-to-one" cfc="User" fkcolumn="userID";
property name="name" ormtype="string";
property name="deleteYN" ormtype="boolean";
property name="showReportYN" ormtype="boolean";
}
User.cfc
component persistent="true" table="Users"{
property name="userID" ormtype="int" fieldtype="id" generator="identity";
property name="username" ormtype="string";
property name="pwd" ormtype="string";
property name="email" ormtype="string";
property name="Language" fieldtype="many-to-one" cfc="Language" fkcolumn="langID";
property name="createdDate" ormtype="timestamp";
property name="lastLoginDate" ormtype="timestamp";
property name="activatedYN" ormtype="boolean";
}
Error in question:
Lucee 4.5.1.022 Error (java.lang.StackOverflowError)
Message java.lang.StackOverflowError
Cause java.lang.StackOverflowError
Java Stacktrace java.lang.StackOverflowError
at java.util.HashMap$HashIterator.(HashMap.java:1411):1411
at java.util.HashMap$ValueIterator.(HashMap.java:1456):1456
at java.util.HashMap$Values.iterator(HashMap.java:959):959
at java.util.AbstractCollection.toArray(AbstractCollection.java:180):180
at lucee.runtime.orm.hibernate.SessionFactoryData.getDataSources(SessionFactoryData.java:314):314
at lucee.runtime.orm.hibernate.HibernateORMSession.getDataSources(HibernateORMSession.java:850):850
at lucee.runtime.db.DatasourceManagerImpl.add(DatasourceManagerImpl.java:111):111
at lucee.runtime.PageContextImpl.getORMSession(PageContextImpl.java:3138):3138
at lucee.runtime.orm.ORMUtil.getSession(ORMUtil.java:59):59
at lucee.runtime.orm.ORMUtil.getSession(ORMUtil.java:55):55
at lucee.runtime.orm.hibernate.tuplizer.accessors.CFCGetter.get(CFCGetter.java:71):71
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:230):230
at lucee.runtime.orm.hibernate.tuplizer.AbstractEntityTuplizerImpl.getIdentifier(AbstractEntityTuplizerImpl.java:66):66
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3852):3852
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:80):80
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190):190
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147):147
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219):219
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99):99
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50):50
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206):1206
at lucee.runtime.orm.hibernate.HibernateORMTransaction.begin(HibernateORMTransaction.java:40):40
at lucee.runtime.orm.ORMConnection.(ORMConnection.java:61):61
at lucee.runtime.orm.ORMDatasourceConnection.(ORMDatasourceConnection.java:52):52
at lucee.runtime.db.DatasourceManagerImpl._add(DatasourceManagerImpl.java:122):122
at lucee.runtime.db.DatasourceManagerImpl.add(DatasourceManagerImpl.java:113):113
at lucee.runtime.PageContextImpl.getORMSession(PageContextImpl.java:3138):3138
at lucee.runtime.orm.ORMUtil.getSession(ORMUtil.java:59):59
at lucee.runtime.orm.ORMUtil.getSession(ORMUtil.java:55):55
at lucee.runtime.orm.hibernate.tuplizer.accessors.CFCGetter.get(CFCGetter.java:71):71
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:230):230
at lucee.runtime.orm.hibernate.tuplizer.AbstractEntityTuplizerImpl.getIdentifier(AbstractEntityTuplizerImpl.java:66):66
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3852):3852
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:80):80
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190):190
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147):147
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219):219
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99):99
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50):50
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206):1206
at lucee.runtime.orm.hibernate.HibernateORMTransaction.begin(HibernateORMTransaction.java:40):40
at lucee.runtime.orm.ORMConnection.(ORMConnection.java:61):61
at lucee.runtime.orm.ORMDatasourceConnection.(ORMDatasourceConnection.java:52):52
at lucee.runtime.db.DatasourceManagerImpl._add(DatasourceManagerImpl.java:122):122
A few refresh later...
Lucee 4.5.1.022 Error (java.lang.StackOverflowError)
Message java.lang.StackOverflowError
Cause java.lang.StackOverflowError
Java Stacktrace java.lang.StackOverflowError
at org.hibernate.util.IdentityMap.entries(IdentityMap.java:93):93
at org.hibernate.event.def.AbstractFlushingEventListener.prepareCollectionFlushes(AbstractFlushingEventListener.java:179):179
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:92):92
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50):50
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206):1206
at lucee.runtime.orm.hibernate.HibernateORMTransaction.begin(HibernateORMTransaction.java:40):40
at lucee.runtime.orm.ORMConnection.(ORMConnection.java:61):61
at lucee.runtime.orm.ORMDatasourceConnection.(ORMDatasourceConnection.java:52):52
at lucee.runtime.db.DatasourceManagerImpl._add(DatasourceManagerImpl.java:122):122
at lucee.runtime.db.DatasourceManagerImpl.add(DatasourceManagerImpl.java:113):113
at lucee.runtime.PageContextImpl.getORMSession(PageContextImpl.java:3138):3138
at lucee.runtime.orm.ORMUtil.getSession(ORMUtil.java:59):59
at lucee.runtime.orm.ORMUtil.getSession(ORMUtil.java:55):55
at lucee.runtime.orm.hibernate.tuplizer.accessors.CFCGetter.get(CFCGetter.java:71):71
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:230):230
at lucee.runtime.orm.hibernate.tuplizer.AbstractEntityTuplizerImpl.getIdentifier(AbstractEntityTuplizerImpl.java:66):66
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3852):3852
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:80):80
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190):190
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147):147
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219):219
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99):99
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50):50
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206):1206
at lucee.runtime.orm.hibernate.HibernateORMTransaction.begin(HibernateORMTransaction.java:40):40
at lucee.runtime.orm.ORMConnection.(ORMConnection.java:61):61
at lucee.runtime.orm.ORMDatasourceConnection.(ORMDatasourceConnection.java:52):52
at lucee.runtime.db.DatasourceManagerImpl._add(DatasourceManagerImpl.java:122):122
at lucee.runtime.db.DatasourceManagerImpl.add(DatasourceManagerImpl.java:113):113
at lucee.runtime.PageContextImpl.getORMSession(PageContextImpl.java:3138):3138
at lucee.runtime.orm.ORMUtil.getSession(ORMUtil.java:59):59
at lucee.runtime.orm.ORMUtil.getSession(ORMUtil.java:55):55
at lucee.runtime.orm.hibernate.tuplizer.accessors.CFCGetter.get(CFCGetter.java:71):71
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:230):230
at lucee.runtime.orm.hibernate.tuplizer.AbstractEntityTuplizerImpl.getIdentifier(AbstractEntityTuplizerImpl.java:66):66
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3852):3852
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:80):80
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190):190
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147):147
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219):219
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99):99
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50):50
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206):1206
Update #1
Using any sort of ORM code or trying to load any entity, will yield this error.
I do have an entity for Game, I failed to paste the relevant code.
I changed the entity and get the same errors:
transaction{
qryInsert = EntityNew("Game");
}
Got a new error this time though, before refreshing and falling into the same stack traces specified earlier.
Lucee 4.5.1.022 Error (java.lang.StackOverflowError)
Message java.lang.StackOverflowError
Cause java.lang.StackOverflowError
Java Stacktrace java.lang.StackOverflowError
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3852):3852
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:80):80
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190):190
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147):147
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219):219
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99):99
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50):50
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206):1206
at lucee.runtime.orm.hibernate.HibernateORMTransaction.begin(HibernateORMTransaction.java:40):40
at lucee.runtime.orm.ORMConnection.(ORMConnection.java:61):61
at lucee.runtime.orm.ORMDatasourceConnection.(ORMDatasourceConnection.java:52):52
Update #2
ORM settings:
<cfset THIS.ormEnabled = true>
<cfset THIS.datasource = "abc">
<cfset THIS.ormSettings = {logsql = true, cfclocation="entity", dbCreate = "none", dialect = "MySQLwithInnoDB"}>
<cfset THIS.invokeImplicitAccessor = true>
Update #3
Solution, adding autoManageSession in my ORM settings:
<cfset THIS.ormSettings = {logsql = true, cfclocation="entity", dbCreate = "none", dialect = "MySQLwithInnoDB", autoManageSession = false}>

I suspect the error may be related to this known issue: To work around it, try adding autoManageSession=false to your ormsettings.

In the examples you gave, you're trying to load a 'Game' entity, which you don't have defined (or at least didn't include). I suspect that the stacktraces you're getting are coming from it trying to dump too much data.
What happens if you try something like:
<cfscript>
transaction{
qryInsert = EntityNew("Season");
qryInsert.setName('testing');
EntitySave(qryInsert);
}
</cfscript>

Related

How to check native code error in cfcatch block?

I have cfcatch block that should catch any exception. Once error detected I build custom function that takes NativeErrorCode as an argument. If error code is one that I'm looking for that indicates duplicate/PK violation I have custom message that will return to the user. If error code is not one that I'm looking for then global message will be returned. However, I run in the problem where ColdFusion returned error message that NativeErrorCode does not exist. I know that Native Error Code is reserved for database type. Is there a way to check the type and prevent this problem or there is better way to fix this issue? Here is my code example:
<cftry>
// Stored procedure call
<cfcatch type="any">
<cfset local.fnResults = {status : "400", message : Application.functions.errorCatch(cfcatch.NativeErrorCode)}>
</cfcatch>
</cftry>
public string function errorCatch(required string ErrorCode) {
local.message = "";
if(arguments.ErrorCode EQ 2627){
local.message = "Error! Cannot insert duplicate value.";
}else{
local.message = "Error! Please contact your administrator.";
}
return message;
}
You can see above how my errorCatch function works and what code I'm checking. I still want cfcatch to grab any exception in my code not just database errors.
Two ways come to mind for handling your branching catch logic, have 2 catch blocks, or check the catch object has the data you want.
In my first example I added a catch block exclusively for database errors. If the type of the error is database a Native Error Code will be included or be -1 if the database driver doesn't include one. For the any argument, I just added your default return string. You may want to have custom logic that would handle non-database type exceptions.
<cftry>
// Stored procedure call
<cfcatch type="database">
<cfset local.fnResults = {status : "400", message : Application.functions.errorCatch(cfcatch.NativeErrorCode)}>
</cfcatch>
<cfcatch type="any">
//Non database related error
<cfset local.fnResults = "Error! Please contact your administrator.">
</cfcatch>
</cftry>
In my second Example I just updated your errorCatch function with a check that a NativeErrorCode exist before we try to pass it.
<cfcatch type="any">
//Passing the default error code value, you may want custom logic here
<cfset local.fnResults = {
status : "400",
message : Application.functions.errorCatch( cfcatch.keyExists("NativeErrorCode")?cfcatch.NativeErrorCode:-1)
}>
</cfcatch>

Mock a message from a 3rd party system in Mule using MUnit

I'm writing a test suite (using Munit) for a Mule application that is processing new data coming from an instance of Magento. One of my flows is polling Magento for new customers and the message it receives is of type: com.magento.api.CustomerCustomerEntity
I'm wondering how I'd mock this so that in my test case, when the Magento message processor is called I can return a payload of the same type and make the appropriate assertations?
Currently my Munit test looks as follows:
<mock:config name="mock_MagentoToSalesforce" doc:name="Mock configuration"/>
<spring:beans>
<spring:import resource="classpath:MagentoToSalesforce.xml"/>
<spring:bean id="myBean" name="myBean" class="com.magento.api.CustomerCustomerEntity">
<spring:property name="email" value="test#test.com"/>
</spring:bean>
</spring:beans>
<munit:test name="MagentoToSalesforce-test-getCustomersFlowTest" description="Test">
<mock:when config-ref="mock_MagentoToSalesforce" messageProcessor=".*:.*" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute whereValue-ref="#[string:Get New Customers]" name="doc:name"/>
</mock:with-attributes>
<mock:then-return payload-ref="#[app.registry.myBean]"/>
</mock:when>
<flow-ref name="getCustomers" doc:name="Flow-ref to getCustomers"/>
</munit:test>
And the flow I'm trying to test is:
<flow name="getCustomers" processingStrategy="synchronous">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="30" timeUnit="SECONDS"/>
<watermark variable="watermark" default-expression="#[new org.mule.el.datetime.DateTime().plusYears(-30)]" update-expression="#[new org.mule.el.datetime.DateTime().plusYears(-0)]" selector-expression="#[new org.mule.el.datetime.DateTime(payload.created_at, 'yyyy-MM-dd HH:mm:ss')]"/>
<magento:list-customers config-ref="Magento" filter="dsql:SELECT confirmation,created_at,created_in,customer_id,dob,email,firstname,group_id,increment_id,lastname,middlename,password_hash,prefix,store_id,suffix,taxvat,updated_at,website_id FROM CustomerCustomerEntity WHERE updated_at > '#[flowVars.watermark]'" doc:name="Get New Customers"/>
</poll>
<foreach doc:name="For Each">
<data-mapper:transform config-ref="MagentoCustomer_To_SalesforceContact" doc:name="Map Customer to SFDC Contact">
<data-mapper:input-arguments>
<data-mapper:input-argument key="ContactSource">Magento</data-mapper:input-argument>
</data-mapper:input-arguments>
</data-mapper:transform>
<flow-ref name="upsertSalesforceContactFlow" doc:name="upsertSalesforceContactFlow"/>
</foreach>
</flow>
Update following Ryan's answer:
Changed the expression to return a payload of #[ent = new com.magento.api.CustomerCustomerEntity(); ent.setEmail('test#test.com'); return [ent];] - note, changed the method to setEmail to match the documentation here. The error I get with this is:
ERROR 2015-06-22 09:58:34,719 [main] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Object "org.mule.transport.NullPayload" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException). Message payload is of type: NullPayload
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Object "org.mule.transport.NullPayload" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException)
org.mule.util.collection.EventToMessageSequenceSplittingStrategy:64 (null)
2. Object "org.mule.transport.NullPayload" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException). Message payload is of type: NullPayload (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.IllegalArgumentException: Object "org.mule.transport.NullPayload" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}"
at org.mule.util.collection.EventToMessageSequenceSplittingStrategy.split(EventToMessageSequenceSplittingStrategy.java:64)
at org.mule.util.collection.EventToMessageSequenceSplittingStrategy.split(EventToMessageSequenceSplittingStrategy.java:25)
at org.mule.routing.CollectionSplitter.splitMessageIntoSequence(CollectionSplitter.java:29)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
One way is to build up the object yourself using the constructor or properties/setters.
From the docs:
http://mulesoft.github.io/magento-connector/2.1.2/java/com/magento/api/CustomerCustomerEntity.html
<mock:then-return payload-ref="#[ent = new com.magento.api.CustomerCustomerEntity(); ent.email('test#test.com'); return ent;]"/>
You can also create these objects aS reusable spring beans and reference them from MEL.
<bean class="com.magento.api.CustomerCustomerEntity" id="myEntityWithEmail">
<property name="email" value="test#test.com" />
</bean>
<mock:then-return payload-ref="#[app.registry.myEntityWithEmail]"/>
After your update I can see that you sre using a foreach which expects a collection or iterable. YOu can return a collection of you custom object simply in MEL using: [] for example:
#[ent = new com.magento.api.CustomerCustomerEntity(); ent.email('test#test.com'); return [ent];]
More on MEL here: https://developer.mulesoft.com/docs/display/current/Mule+Expression+Language+MEL
Or again you can use Spring to return a list:
<util:list id="entities">
<ref bean="myEntityWithEmail" />
</util:list>

Element VAR is undefined in ATTRIBUTES ColdFusion 11

I am trying to call a method from a java class but I am getting an exception I haven't seen before.
This is what I get back when I am calling the class and one of the methods and how I got this
<cfdump var="#nlp#">
<cfdump var="#nlp.run()#">
And this is the exception I got when I am trying to dump the method
19:12:31.031 - Expression Exception - in Z:/Sites/xamplifier/views/surveyreporting/wordcloud.cfm : line 157
Element VAR is undefined in ATTRIBUTES.
Am I calling the method in a wrong way? This is how we had the code on CF9 and everything works but CF 11 seems to have issues...
It looks like the Open_NPL run() method is generating an exception, which is caught and causes it to return null. See here: Open_NPS Source
Agree with the other answers, you'll just have to test for NULL to avoid the CF exception, and dig into the Java to determine the root cause.
The Java method is returning NULL, which in ColdFusion is the same as not being defined. You need to capture the result and test it.
<cfset local = {}><!--- if inside a function, this isn't necessary --->
<cfset local.result = nlp.run() >
<cfif not isNull( local.result ) >
<cfdump var="local.result">
<cfelse>
NULL!
</cfif>

Mailgun & CfMailGun component. How to implement it

I'm trying to use the component [https://github.com/DominicWatson/cfmailgun][1] to send email (using SendMessage ()) through mailgun.
I am not able to use it. I have read the documentation at this address: http://dominicwatson.github.io/cfmailgun/
But I can not implement it. The author has not included a complete example.
He added only this:
mailGunClient = new MailGunClient( apiKey = myPrivateApiKey );
Can anyone help me with a more complete example?
Thank you.
Edit:
After some tests, I've tried with:
<cfscript>
myPrivateApiKey = "key-123456789";
mailGunClient = new MailGunClient( apiKey = myPrivateApiKey );
mailGunClient.sendMessage(domain = 'domain.com', from='info#domain.com', to='to#gmail.com', subject='Test', text='hello world', html='<b>hello world</b>');
</cfscript>
But I get the error:
MailGun request failure. ['from' parameter is missing]
Edit 2
I solved it (thanks to the help of the author of the script). It was a problem in the component.
Anywhere you see <cfhttpparam ... name="#key#" ..., changing that to <cfhttpparam ... name="#LCase( key )#" ...

How do you capture errors for an entire Application in ColdFusion?

I am currently trying to capture all errors in my application by including the following code in Application.cfc:
<cffunction name="onError">
<!--- The onError method gets two arguments:
An exception structure, which is identical to a cfcatch variable.
The name of the Application.cfc method, if any, in which the error
happened. --->
<cfargument name="Except" required=true/>
<cfargument type="String" name = "EventName" required=true/>
<!--- Log all errors in an application-specific log file. --->
<cflog file="#THIS.NAME#" type="error" text="Event Name: #Eventname#" >
<cflog file="#THIS.NAME#" type="error" text="Message: #Except.message#">
<!--- Throw validation errors to ColdFusion for handling. --->
<cfif Find("coldfusion.filter.FormValidationException", Arguments.Except.StackTrace)>
<cfthrow object="#Except#">
<cfelse>
<cfoutput>
<h1>#Eventname#</h1>
</cfoutput>
<cfdump var="#Except#">
</cfif>
</cffunction>
Some of that is borrowed from other examples I have seen (which I don't fully understand). I ultimately want to show some kind of graceful error page to solicit feedback from the user and then log/email the error. This seems to catch a lot of errors, but not all. I don't want to use try/catch everywhere if I don't have to either. Any suggestions?
There is also an overall ColdFusion error handler that you can define in the ColdFusion administrator. Under the Server Settings > Settings, scroll down to the bottom and set the option for "Site-wide Error Handler".
Check this in the docs as well About error handling in ColdFusion
Using shared hosting shouldnt be an issue, just ask your hosr what the error templates are, if they are clued up about cf then they will have them setup.
Wr use error.cfm and 404.cfm fot example which go in the root of every customers site.
The "OnError" method within the Application.cfc will only catch the errors where they have not previously been caught by a user defined try/catch statement.
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=appFramework_13.html
With this said, I think it to be a good idea to have try catch statements within your code where necessary (situations where you cannot degrade gracefully). What I like to do is instantiate a cfc that wraps all exception handling. This cfc can then contain the actual error handling logic and all that the OnError method will need to do is instantiate the correct component and "control" the error.
A very simple illustration:
<cfscript>
/** Application.cfc **/
public function onError(required exception, required string eventName)
{
var factory = new App.ExceptionFactory();
var e = factory.getNewException(arguments.eventName, arguments.exception);
if (e.logError()) {
/** we cauld also have a logging cfc etc **/
var loggingFile = new App.SomeLoggingCfc(arguments.eventName, arguments.exception);
loggingFile.commitLog();
}
if (e.debugError()) {
// show developer info here
}
/** Throw the exception **/
e.throwException();
}
/** App.ExceptionFactory **/
public ExceptionFactory function getNewException(required string eventName, required exception)
{
return new "App.#exception.type#"(argumentCollection = arguments);
}
/** App.Exception.CustomException **/
public boolean function logError()
{
/** log the error **/
}
public boolean function debugError() {}
public function throwException()
{
/** do what you want here **/
}
</cfscript>