Skip to content

Commit

Permalink
📦 NEW: Add error setter/getter for tasks
Browse files Browse the repository at this point in the history
Adds easier retrieval of task errors - for example, attempting to iterate over a HashMap will throw an illegal argument exception, but the task shows as "completed".
  • Loading branch information
michaelborn committed Jan 11, 2022
1 parent fa060c4 commit aa4fcc2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/cbelasticsearch/models/Task.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ component accessors="true" {
property name="parent_task_id";
property name="headers";
property name="response";
property name="error";
property
name ="completed"
type ="boolean"
Expand All @@ -34,6 +35,9 @@ component accessors="true" {

public function populate( struct properties ){
if ( arguments.keyExists( "properties" ) ) {
if ( structKeyExists( arguments.properties, "error" ) ){
setError( arguments.properties.error );
}
if ( structKeyExists( arguments.properties, "task" ) ) {
var taskProperties = arguments.properties.task;
if ( structKeyExists( arguments.properties, "completed" ) ) {
Expand Down
40 changes: 40 additions & 0 deletions tests/specs/unit/TaskTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,46 @@ component extends="coldbox.system.testing.BaseTestCase" {

expect( variables.model.isComplete() ).toBeTrue();
} );
it( "can get error details", function(){
expect( variables.model ).toBeInstanceOf( "cbElasticsearch.models.Task" );
var testTask = {
"completed" : false,
"task" : {
"node" : "oTUltX4IQMOUUVeiohTt8A",
"id" : 464,
"type" : "transport",
"action" : "indices:data/read/search",
"description" : "indices[test], types[test], search_type[QUERY_THEN_FETCH], source[{""query"":...}]",
"start_time_in_millis" : 1483478610008,
"running_time_in_nanos" : 13991383,
"cancellable" : true
},
"error" : {
"position": {
"offset": 33,
"start": 16,
"end": 64
},
"script": " for ( test in ctx._source ){ ...",
"reason": "runtime error",
"type": "script_exception",
"lang": "painless",
"caused_by": {
"reason": "Cannot iterate over [java.util.HashMap]",
"type": "illegal_argument_exception"
},
"script_stack": [
"for ( case in ctx._source ){ ",
" ^---- HERE"
]
}
};
variables.model.populate( testTask );

expect( variables.model.getCompleted() ).toBe( testTask.completed );
expect( variables.model.getError() ).toBeTypeOf( "struct" )
.toHaveKey( "reason" );
} );
} );
}

Expand Down

0 comments on commit aa4fcc2

Please sign in to comment.