avniproject / avni-client

Android app for the fieldworkers.
https://avniproject.org
GNU Affero General Public License v3.0
7 stars 20 forks source link

Rules returning null in decisions. #236

Open ghost opened 5 years ago

ghost commented 5 years ago

Reproduction steps

  1. Write a decision rule that returns null as a decision object.
  2. Run the workflow(registration/enrolment/encounter) that invokes the rule written in step 1 on the android app.
  3. If the rule is written in the old style then the app will crash but if the rule is written in a new style then the rule will be ignored silently and there will be a cryptic error in RuleFailureTelemetry.

Expected Behaviour This is an error that we can easily validate so we should notify the implementer using rule failure telemetry with a clear message that their rule returns null object so they can fix their rule. Right now the app behaviour is to crash(if old rule) or ignore silently and give cryptic null pointer error message in rule failure telemetry(if new rule).

See RuleEvaluationService.js
validateDecisions(d, ruleUUID, individualUUID) {
    return _.merge(..._.map(d, (decisions, decisionType) => {
        return {
            [decisionType]: decisions.filter(obj => this.checkConceptForRule(obj.name, ruleUUID, individualUUID))
                .map(obj => this.filterValues(obj, ruleUUID, individualUUID))

        }
    }));
}

Error

TypeError
/Users/vinay/code/sf/openchs-client/packages/openchs-android/src/service/RuleEvaluationService.js:106
Fatal error: null is not an object (evaluating 't.name')
Nov 5th, 2019, 11:21:08 IST

STACKTRACE

TypeError Fatal error: null is not an object (evaluating 't.name') 
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/service/RuleEvaluationService.js:106:85 
    [native code] filter
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/service/RuleEvaluationService.js:106:49 
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/lodash/lodash.js:3549:35 
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/lodash/lodash.js:4911:23 
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/lodash/lodash.js:2996:31 baseForOwn
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/lodash/lodash.js:4880:26 
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/lodash/lodash.js:3548:15 baseMap
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/lodash/lodash.js:9556:18 map
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/service/RuleEvaluationService.js:104:32 value
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/service/RuleEvaluationService.js:92:46 
    [native code] reduce
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/service/RuleEvaluationService.js:90:20 value
    [native code] value
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/service/RuleEvaluationService.js:132:38 value
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/state/ProgramEncounterState.js:73:49 value
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/state/AbstractDataEntryState.js:125:45 value
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/action/program/ProgramEncounterActions.js:61:40 value
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/reducer/Reducer.js:23:44 
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/redux/lib/combineReducers.js:132:36 
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/redux/lib/createStore.js:179:36 dispatch
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/framework/view/AbstractComponent.js:56:15 value
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/views/program/ProgramEncounterView.js:69:28 value
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/views/program/ProgramEncounterView.js:139:45 func
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/src/views/common/WizardButtons.js:59:54 onPress
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Components/Touchable/TouchableNativeFeedback.android.js:213:45 touchableHandlePress
    [native code] touchableHandlePress
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Components/Touchable/Touchable.js:878:34 _performSideEffectsForTransition
    [native code] _performSideEffectsForTransition
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Components/Touchable/Touchable.js:777:44 _receiveSignal
    [native code] _receiveSignal
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Components/Touchable/Touchable.js:488:24 touchableHandleResponderRelease
    [native code] touchableHandleResponderRelease
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:48:15 invokeGuardedCallbackImpl
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:66:34 invokeGuardedCallback
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:79:30 invokeGuardedCallbackAndCatchFirstError
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:173:42 executeDispatch
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:222:24 executeDispatchesAndReleaseTopLevel
    [native code] forEach
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:206:35 forEachAccumulated
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:1064:26 
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:7078:14 _batchedUpdatesImpl
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:1025:31 batchedUpdates
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:1045:17 _receiveRootNodeIDEvent
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-prod.js:1110:30 receiveTouches
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:366:47 value
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:106:26 
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:314:8 value
    /Users/vinay/code/sf/openchs-client/packages/openchs-android/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:105:17 value
    [native code] value

THREADS
......
......
hithacker commented 4 years ago

Time estimate: 2 hours. Point estimate: 1.

vinayvenu commented 1 year ago

This will need to be verified first.