Skip to content

Commit

Permalink
[#4174] implement support of iRODS error codes to the rule language
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-hao authored and trel committed Nov 22, 2018
1 parent 0031ad6 commit 172fc67
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 33 deletions.
2 changes: 2 additions & 0 deletions lib/core/include/rodsErrorTable.h
Expand Up @@ -41,11 +41,13 @@
namespace {
namespace irods_error_map_construction {
std::map<const int, const std::string> irods_error_map;
std::map<const std::string, const int> irods_error_name_map;

//We pass the variable as a const reference here to silence
//unused variable warnings in a controlled manner
int create_error( const std::string& err_name, const int err_code, const int& ) {
irods_error_map.insert( std::pair<const int, const std::string>( err_code, err_name ) );
irods_error_name_map.insert( std::pair<const std::string, const int>( err_name, err_code ) );
return err_code;
}
}
Expand Down
@@ -1,6 +1,9 @@
/* For copyright information please refer to files in the COPYRIGHT directory
*/

#define MAKE_IRODS_ERROR_MAP
#include "rodsErrorTable.h"
const static std::map<const std::string, const int> irods_error_name_map = irods_error_map_construction::irods_error_name_map;
#include "reFuncDefs.hpp"
#include "utils.hpp"
#include "restructs.hpp"
Expand Down Expand Up @@ -75,25 +78,32 @@ Res* evaluateExpression3( Node *expr, int applyAll, int force, ruleExecInfo_t *r
res->exprType = newSimpType( T_UNSPECED, r );
break;
case TK_TEXT:
fd = ( FunctionDesc * )lookupFromEnv( ruleEngineConfig.extFuncDescIndex, expr->text );
if ( fd != NULL && fd->exprType != NULL ) {
int nArgs = 0;
ExprType *type = fd->exprType;
while ( getNodeType( type ) == T_CONS && strcmp( type->text, FUNC ) == 0 ) {
type = type->subtrees[1];
nArgs ++;
}
if ( nArgs == 0 ) {
Node *appNode = newPartialApplication( expr, newTupleRes( 0, NULL, r ), 0, r );
res = evaluateFunction3( appNode, applyAll, expr, env, rei, reiSaveFlag, errmsg, r );
}
else {
{
auto itr = irods_error_name_map.find(expr->text);
if(itr != irods_error_name_map.end()) {
res->exprType = newSimpType( T_UNSPECED, r );
} else {
fd = ( FunctionDesc * )lookupFromEnv( ruleEngineConfig.extFuncDescIndex, expr->text );
if ( fd != NULL && fd->exprType != NULL ) {
int nArgs = 0;
ExprType *type = fd->exprType;
while ( getNodeType( type ) == T_CONS && strcmp( type->text, FUNC ) == 0 ) {
type = type->subtrees[1];
nArgs ++;
}
if ( nArgs == 0 ) {
Node *appNode = newPartialApplication( expr, newTupleRes( 0, NULL, r ), 0, r );
res = evaluateFunction3( appNode, applyAll, expr, env, rei, reiSaveFlag, errmsg, r );
}
else {
res->exprType = newSimpType( T_UNSPECED, r );
}
}
else {
res->exprType = newSimpType( T_UNSPECED, r );
}
}
}
else {
res->exprType = newSimpType( T_UNSPECED, r );
}
break;


Expand Down Expand Up @@ -169,25 +179,32 @@ Res* evaluateExpression3( Node *expr, int applyAll, int force, ruleExecInfo_t *r
res = evaluateVar3( expr->text, expr, rei, env, errmsg, r );
break;
case TK_TEXT:
fd = ( FunctionDesc * )lookupFromEnv( ruleEngineConfig.extFuncDescIndex, expr->text );
if ( fd != NULL && fd->exprType != NULL ) {
int nArgs = 0;
ExprType *type = fd->exprType;
while ( getNodeType( type ) == T_CONS && strcmp( type->text, FUNC ) == 0 ) {
type = type->subtrees[1];
nArgs ++;
}
if ( nArgs == 0 ) {
Node *appNode = newPartialApplication( expr, newTupleRes( 0, NULL, r ), 0, r );
res = evaluateFunction3( appNode, applyAll, expr, env, rei, reiSaveFlag, errmsg, r );
}
else {
res = newFuncSymLink( expr->text, nArgs, r );
{
auto itr = irods_error_name_map.find(expr->text);
if(itr != irods_error_name_map.end()) {
res = newIntRes(r, itr->second);
} else {
fd = ( FunctionDesc * )lookupFromEnv( ruleEngineConfig.extFuncDescIndex, expr->text );
if ( fd != NULL && fd->exprType != NULL ) {
int nArgs = 0;
ExprType *type = fd->exprType;
while ( getNodeType( type ) == T_CONS && strcmp( type->text, FUNC ) == 0 ) {
type = type->subtrees[1];
nArgs ++;
}
if ( nArgs == 0 ) {
Node *appNode = newPartialApplication( expr, newTupleRes( 0, NULL, r ), 0, r );
res = evaluateFunction3( appNode, applyAll, expr, env, rei, reiSaveFlag, errmsg, r );
}
else {
res = newFuncSymLink( expr->text, nArgs, r );
}
}
else {
res = newFuncSymLink( expr->text, 1, r );
}
}
}
else {
res = newFuncSymLink( expr->text, 1, r );
}
break;


Expand Down Expand Up @@ -538,6 +555,8 @@ Res *evaluateFunctionApplication( Node *func, Node *arg, int applyAll, Node *nod
char errbuf[ERR_MSG_LEN];
int discardResult = ( reiSaveFlag & DISCARD_EXPRESSION_RESULT ) != 0;
switch ( getNodeType( func ) ) {
case N_VAL:
return func;
case N_SYM_LINK:
case N_PARTIAL_APPLICATION:
res = newPartialApplication( func, arg, RES_FUNC_N_ARGS( func ) - 1, r );
Expand Down
19 changes: 19 additions & 0 deletions scripts/irods/test/test_native_rule_engine_plugin.py
Expand Up @@ -406,3 +406,22 @@ def test_delay_block_with_output_param__3906(self):

# Bounce server to get back original settings
irodsctl.restart()

@unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-irods_rule_language', 'only applicable for irods_rule_language REP')
def test_SYS_NOT_SUPPORTED__4174(self):

rule_file = 'test_SYS_NOT_SUPPORTED__4174.r'
rule_string = '''
test_SYS_NOT_SUPPORTED__4174_rule {
fail(SYS_NOT_SUPPORTED);
}
INPUT null
OUTPUT ruleExecOut
'''
with open(rule_file, 'w') as f:
f.write(rule_string)

self.admin.assert_icommand('irule -F ' + rule_file, 'STDERR_SINGLELINE','SYS_NOT_SUPPORTED')
os.unlink(rule_file)

0 comments on commit 172fc67

Please sign in to comment.