Skip to content

Commit

Permalink
BL-913 resolve - fix throw with exception as first argument
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Jan 10, 2025
1 parent c745944 commit ae70755
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Throw extends BIF {
public Throw() {
super();
declaredArguments = new Argument[] {
new Argument( false, "String", Key.message ),
new Argument( false, "any", Key.message ),
new Argument( false, "String", Key.type ),
new Argument( false, "String", Key.detail ),
new Argument( false, "String", Key.errorcode ),
Expand Down Expand Up @@ -64,7 +64,11 @@ public Throw() {
* CustomException will be thrown and this object will be used as the cause.
*/
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) {
Throwable exceptionToThrow;
Throwable exceptionToThrow;
if ( arguments.get( Key.message ) instanceof Throwable ) {
arguments.put( Key.object, arguments.get( Key.message ) );
arguments.put( Key.message, null );
}
String message = arguments.getAsString( Key.message );
String detail = arguments.getAsString( Key.detail );
String errorcode = arguments.getAsString( Key.errorcode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Throw extends Component {
public Throw() {
super();
declaredAttributes = new Attribute[] {
new Attribute( Key.message, "String" ),
new Attribute( Key.message, "any" ),
new Attribute( Key.type, "String" ),
new Attribute( Key.detail, "String" ),
new Attribute( Key.errorcode, "String" ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,22 @@ public void testThrowJustType2() {
assertThat( variables.get( Key.of( "type" ) ) ).isEqualTo( "DivideByZero" );
}

@Test
public void testThrowObjectUnnamed() {
//@formatter:off
instance.executeSource( """
try {
throw( type="MyCustomException" );
} catch ( e ) {
try{
throw( e );
} catch( e2 ) {
type = e2.type;
}
}
""", context, BoxSourceType.CFSCRIPT );
//@formatter:on
assertThat( variables.get( Key.of( "type" ) ) ).isEqualTo( "MyCustomException" );
}

}

0 comments on commit ae70755

Please sign in to comment.