Skip to content

Commit

Permalink
Stubbed out exception classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed Sep 19, 2023
1 parent 1b9c79f commit 2545117
Show file tree
Hide file tree
Showing 11 changed files with 488 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import ortus.boxlang.runtime.dynamic.casters.CastAttempt;
import ortus.boxlang.runtime.dynamic.casters.DoubleCaster;
import ortus.boxlang.runtime.scopes.Key;
import ortus.boxlang.runtime.types.exceptions.ApplicationException;
import ortus.boxlang.runtime.types.exceptions.BoxLangException;
import ortus.boxlang.runtime.types.exceptions.KeyNotFoundException;

Expand Down Expand Up @@ -92,7 +93,7 @@ public class DynamicObject implements IReferenceable {
BoxLangException.detailKey,
BoxLangException.typeKey,
BoxLangException.tagContextKey,
BoxLangException.ExtendedInfoKey
ApplicationException.ExtendedInfoKey
) );
/**
* This is a map of primitive types to their native Java counterparts
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* [BoxLang]
*
* Copyright [2023] [Ortus Solutions, Corp]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ortus.boxlang.runtime.types.exceptions;

import ortus.boxlang.runtime.scopes.Key;

/**
* Base exception for all custom exceptions thrown by the user
*/
public class ApplicationException extends BoxLangException {

public static final Key ExtendedInfoKey = Key.of( "extendedInfo" );

/**
* Custom error message; information that the default exception handler does not display.
*/
public String extendedInfo = "";

/**
* Constructor
*
* @param message The message
*/
public ApplicationException( String message ) {
this( message, null, null, null );
}

/**
* Constructor
*
* @param message The message
* @param errorCode The errorCode
*/
public ApplicationException( String message, Throwable cause ) {
this( message, null, null, cause );
}

/**
* Constructor
*
* @param message The message
* @param errorCode The errorCode
*/
public ApplicationException( String message, String extendedInfo ) {
this( message, null, extendedInfo, null );
}

/**
* Constructor
*
* @param message The message
* @param detail The detail
* @param errorCode The errorCode
* @param cause The cause
*/
public ApplicationException( String message, String detail, String extendedInfo, Throwable cause ) {
super( message, "application", cause );
this.detail = detail;
this.extendedInfo = extendedInfo;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,20 @@
import ortus.boxlang.runtime.scopes.Key;

/**
* This exception is thrown when a cast can't be done on any type
* This is the root exception for all exceptions thrown by BoxLang.
*/
public class BoxLangException extends RuntimeException {
public abstract class BoxLangException extends RuntimeException {

public static final Key messageKey = Key.of( "message" );
public static final Key detailKey = Key.of( "detail" );
public static final Key typeKey = Key.of( "type" );
public static final Key tagContextKey = Key.of( "tagContext" );
public static final Key NativeErrorCodeKey = Key.of( "NativeErrorCode" );
public static final Key SQLStateKey = Key.of( "SQLState" );
public static final Key SqlKey = Key.of( "Sql" );
public static final Key queryErrorKey = Key.of( "queryError" );
public static final Key whereKey = Key.of( "where" );
public static final Key ErrNumberKey = Key.of( "ErrNumber" );
public static final Key MissingFileNameKey = Key.of( "MissingFileName" );
public static final Key LockNameKey = Key.of( "LockName" );
public static final Key LockOperationKey = Key.of( "LockOperation" );
public static final Key ErrorCodeKey = Key.of( "ErrorCode" );
public static final Key ExtendedInfoKey = Key.of( "ExtendedInfo" );
public static final Key messageKey = Key.of( "message" );
public static final Key detailKey = Key.of( "detail" );
public static final Key typeKey = Key.of( "type" );
public static final Key tagContextKey = Key.of( "tagContext" );

/**
* Detailed message from the CFML interpreter or specified in a cfthrow tag. When the exception is generated by BoxLang (and not cfthrow), the
* message can contain HTML formatting and can help determine which tag threw the exception.
*/
public String detail = "";
public String detail = "";
/**
* Type: Exception type, as specified in cfcatch.
*
Expand All @@ -59,78 +48,56 @@ public class BoxLangException extends RuntimeException {
* - custom_type: catches the specified custom exception type that is defined in a cfthrow tag
* - searchengine: catches Solr search engine exceptions
* - any: catches all exception types
*
* The type must ALWAYS be set for a BoxLangException by the superclass extending this base class. This will also
* ensure the type string matches the exception class as well.
*/
public String type = "application";
public String type = null;
// TODO:
public String tagContext = "";
public String tagContext = "";

// TODO: Refactor most of these into sub classes
/**
* Applies to type = "database". Native error code associated with exception. Database drivers typically provide error codes to diagnose failing
* database operations. Default value is -1.
*/
public String NativeErrorCode = "";
/**
* Applies to type = "database". SQLState associated with exception. Database drivers typically provide error codes to help diagnose failing database
* operations. Default value is 1.
*/
public String SQLState = "";
/**
* Applies to type = "database". The SQL statement sent to the data source.
*/
public String Sql = "";
/**
* Applies to type ="database". The error message as reported by the database driver.
*/
public String queryError = "";
/**
* Applies to type= "database". If the query uses the cfqueryparam tag, query parameter name-value pairs.
*/
public String where = "";
/**
* Applies to type = "expression". Internal expression error number.
*/
public String ErrNumber = "";
/**
* Applies to type = "missingInclude". Name of file that could not be included.
*/
public String MissingFileName = "";
/**
* Applies to type = "lock". Name of affected lock (if the lock is unnamed, the value is "anonymous").
*/
public String LockName = "";
/**
* Applies to type = "lock". Operation that failed (Timeout, Create Mutex, or Unknown).
*/
public String LockOperation = "";
/**
* Applies to type = "custom". String error code.
*/
public String ErrorCode = "";
/**
* Applies to type = "application" and "custom". Custom error message; information that the default exception handler does not display.
* Constructor
*
* @param message The message
*/
public String ExtendedInfo = "";
public BoxLangException( String message, String type ) {
this( message, "", type, null );
}

/**
* Constructor
*
* @param message Why the cast can't be done
* @param message The message
* @param cause The cause
*/
public BoxLangException( String message ) {
this( message, "", "application", null );
}

public BoxLangException( String message, Throwable cause ) {
this( message, "", "application", cause );
public BoxLangException( String message, String type, Throwable cause ) {
this( message, "", type, cause );
}

/**
* Constructor
*
* @param message The message
* @param detail The detail
* @param type The type
*/
public BoxLangException( String message, String detail, String type ) {
this( message, detail, type, null );
}

/**
* Constructor
*
* @param message The message
* @param detail The detail
* @param type The type
* @param cause The cause
*/
public BoxLangException( String message, String detail, String type, Throwable cause ) {
super( message );
this.detail = detail;
this.type = type;
if ( cause != null ) {
initCause( cause );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* This exception is thrown when a cast can't be done on any type
*/
public class CastException extends BoxLangException {
public class CastException extends ApplicationException {

/**
* Constructor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* [BoxLang]
*
* Copyright [2023] [Ortus Solutions, Corp]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ortus.boxlang.runtime.types.exceptions;

import ortus.boxlang.runtime.scopes.Key;

/**
* Base exception for all custom exceptions thrown by the user
*/
public class CustomException extends ApplicationException {

public static final Key ErrorCodeKey = Key.of( "errorCode" );

/**
* Applies to type = "custom". String error code.
*/
public String errorCode = "";

/**
* Constructor
*
* @param message The message
* @param errorCode The errorCode
*/
public CustomException( String message, String errorCode ) {
this( message, null, errorCode, null, null );
}

/**
* Constructor
*
* @param message The message
* @param detail The detail
* @param errorCode The errorCode
* @param cause The cause
*/
public CustomException( String message, String detail, String errorCode, String extendedInfo, Throwable cause ) {
super( message, detail, extendedInfo, cause );
this.errorCode = errorCode;
}

}
Loading

0 comments on commit 2545117

Please sign in to comment.