Thoughts On Chained And Dependent Algorithm Steps

<!--- Create an array to hold processing errors. --->
<cfset arrErrors = [] />
 
 
<!---
	Process the data in a multi-step dependent algorithm
	where each step depends on the successful completion
	of all the previou steps.
--->
<chain:steps>
 
	<!---
		For the first step, we are going to be uploading
		the selected form file.
	--->
	<chain:try>
 
		<cffile
			action="upload"
			filefield="resume"
			destination="#REQUEST.UploadDirectory#"
			nameconflict="makeunique"
			/>
 
 
		<!--- Make sure this is a CSV file. --->
		<cfif (ListLast( CFFILE.ServerFile, "." ) NEQ "csv")>
 
			<!---
				This was not a valid file extension for
				this process. Throw an error (which will be
				caught by the internal catch mechanism).
			--->
			<chain:throw
				type="File.InvalidExtension"
				message="File extension was not valid"
				detail="The file you uploaded was not valid. Only CSV files can are allowed."
				/>
 
		</cfif>
 
		<!--- Catch any errors that were thrown. --->
		<chain:catch>
 
			<!--- Add error message. --->
			<cfset ArrayAppend(
				arrErrors,
				"There was a problem uploading the file."
				) />
 
		</chain:catch>
	</chain:try>
 
 
	<!---
		For the second step, we are going to process the
		uploaded file into a query.
	--->
	<chain:try>
 
		<!--- Process uploaded document. --->
		<cfset qData = ProcessUpload(
			"#REQUEST.UploadDirectory##CFFILE.ServerFile#"
			) />
 
		<!--- Catch any errors that were thrown. --->
		<chain:catch>
 
			<!--- Add error message. --->
			<cfset ArrayAppend(
				arrErrors,
				"There was a problem importing the data file."
				) />
 
		</chain:catch>
	</chain:try>
 
 
	<!---
		For the last step, we are going to move the query
		data into the database.
	--->
	<chain:try>
 
		<!--- Loop over query and address each record. --->
		<cfloop query="qData">
 
			<cfquery name="qInsert" datasource="test">
				INSERT INTO [table]
				(
					[value]
				) VALUES (
					#qData.value#
				);
			</cfquery>
 
		</cfloop>
 
		<!--- Catch any errors that were thrown. --->
		<chain:catch>
 
			<!--- Add error message. --->
			<cfset ArrayAppend(
				arrErrors,
				"There was a problem inserting the data. Perhaps some of your values were not valid."
				) />
 
		</chain:catch>
	</chain:try>
 
 
	<!---
		Here, we can process any errors that occurred.
		This tag will only be executed if one of the
		above tags failed.
	--->
	<chain:catch>
 
		<!--- Log error. --->
		<cfset LogError( CFCATCH ) />
 
	</chain:catch>
</chain:steps>

For Cut-and-Paste