Repository: oppia/oppia

Issue:
Cannot read properties of null (reading 'size')
<!--
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->

This error occurred recently in production

```
Error: Cannot read properties of null (reading 'size')
    at b.t.save (rte-helper-modal.controller.ts:146:27)
    at fn (angular.js:16548:15), <anonymous>:4:132)
    at e (angular.js:29123:13)
    at b.$eval (angular.js:19523:16)
    at b.$apply (angular.js:19622:20)
    at HTMLInputElement.<anonymous> (angular.js:29127:13)
    at HTMLInputElement.dispatch (jquery.min.js:2:43090)
    at HTMLInputElement.v.handle (jquery.min.js:2:41074)
```

**Additional context** Add details from the logs, like the page the error occurred on. Make sure to anonymize user data like user IDs, exploration IDs, state names, user names, etc. Replace the personal data with appropriate placeholders.

**General instructions**
There are no specific repro steps available for this bug report. The general procedure to fix server errors should be the following:

* Analyze the code in the file where the error occurred and come up with a hypothesis for the reason.
* Get the logic of the proposed fix validated by an Oppia team member (have this discussion on the issue thread).
* Make a PR that fixes the issue, then close the issue on merging the PR. (If the error reoccurs in production, the issue will be reopened for further investigation.)

Cannot read properties of undefined (reading 'getStoryContents')
<!--
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->

This error occurred recently in production

```
Cannot read properties of undefined (reading 'getStoryContents')
    at getStoryContents (webpack:///core/templates/pages/story-editor-page/chapter-editor/chapter-editor-tab.component.ts:38:40)
    at initEditor (webpack:///core/templates/pages/story-editor-page/chapter-editor/chapter-editor-tab.component.ts:71:13)
    at https://www.oppia.org/third_party/static/angularjs-1.8.2/angular.min.js:73:478
    at call (angular.js:396:8)
    at p (angular.js:10642:8)
    at g (angular.js:9942:12)
    at g (angular.js:9945:12)
    at https://www.oppia.org/third_party/static/angularjs-1.8.2/angular.min.js:65:311
    at https://www.oppia.org/third_party/static/angularjs-1.8.2/angular.min.js:71:132
    at d (angular.js:9985:15) 
```

**Additional context** Add details from the logs, like the page the error occurred on. Make sure to anonymize user data like user IDs, exploration IDs, state names, user names, etc. Replace the personal data with appropriate placeholders.

**General instructions**
There are no specific repro steps available for this bug report. The general procedure to fix server errors should be the following:

* Analyze the code in the file where the error occurred and come up with a hypothesis for the reason.
* Get the logic of the proposed fix validated by an Oppia team member (have this discussion on the issue thread).
* Make a PR that fixes the issue, then close the issue on merging the PR. (If the error reoccurs in production, the issue will be reopened for further investigation.)

Cannot read properties of null (reading 'size')
<!--
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->

This error occurred recently in production

```
Error: Cannot read properties of null (reading 'size')
    at b.t.save (rte-helper-modal.controller.ts:146:27)
    at fn (angular.js:16548:15), <anonymous>:4:132)
    at e (angular.js:29123:13)
    at b.$eval (angular.js:19523:16)
    at b.$apply (angular.js:19622:20)
    at HTMLInputElement.<anonymous> (angular.js:29127:13)
    at HTMLInputElement.dispatch (jquery.min.js:2:43090)
    at HTMLInputElement.v.handle (jquery.min.js:2:41074)
```

**Additional context** Add details from the logs, like the page the error occurred on. Make sure to anonymize user data like user IDs, exploration IDs, state names, user names, etc. Replace the personal data with appropriate placeholders.

**General instructions**
There are no specific repro steps available for this bug report. The general procedure to fix server errors should be the following:

* Analyze the code in the file where the error occurred and come up with a hypothesis for the reason.
* Get the logic of the proposed fix validated by an Oppia team member (have this discussion on the issue thread).
* Make a PR that fixes the issue, then close the issue on merging the PR. (If the error reoccurs in production, the issue will be reopened for further investigation.)



Discussion:
Steps to reproduce a possibly related error "The rawLatex or svgFileName for a Math expression should not be empty."

1. Go to the contributor dashboard.
2. Go to the Translate text screen and select a language.
3. Select a lesson to translate.
4. In the RTE editor, choose math component.
5. Enter some valid math character and hit backspace until it is empty.
6. Click on done.
7. See error.
Hi @krishita30j @Rijuta-s could you please prioritise this? I have added some steps to repro in the comment above, I suspect it might be related to this error (happens when a math component data url is null). 

This happens when refreshing the chapter editor page. The `StoryEditorStateService` is not initialized when this happens. Possible fix would be to render the page after the editor service has been initialised.
Steps to reproduce a possibly related error "The rawLatex or svgFileName for a Math expression should not be empty."

1. Go to the contributor dashboard.
2. Go to the Translate text screen and select a language.
3. Select a lesson to translate.
4. In the RTE editor, choose math component.
5. Enter some valid math character and hit backspace until it is empty.
6. Click on done.
7. See error.
Hi @krishita30j @Rijuta-s could you please prioritise this? I have added some steps to repro in the comment above, I suspect it might be related to this error (happens when a math component data url is null). 


Resolving patch:
diff --git a/core/controllers/practice_sessions.py b/core/controllers/practice_sessions.py
--- a/core/controllers/practice_sessions.py
+++ b/core/controllers/practice_sessions.py
@@ -32,7 +32,14 @@ class PracticeSessionsPage(base.BaseHandler):
         'topic_url_fragment': constants.SCHEMA_FOR_TOPIC_URL_FRAGMENTS
     }
     HANDLER_ARGS_SCHEMAS = {
-        'GET': {}
+        'GET': {
+            'selected_subtopic_ids': {
+                'schema': {
+                    'type': 'custom',
+                    'obj_type': 'JsonEncodedInString'
+                }
+            }
+        }
     }
 
     @acl_decorators.can_access_topic_viewer_page
@@ -41,6 +48,30 @@ def get(self, _):
 
         self.render_template('practice-session-page.mainpage.html')
 
+    def handle_exception(self, exception, unused_debug_mode):
+        """Handles exceptions raised by this handler.
+
+        Args:
+            exception: Exception. The exception raised by the handler.
+            unused_debug_mode: bool. Whether the app is running in debug mode.
+        """
+        if isinstance(exception, self.InvalidInputException):
+            (
+                _,
+                _,
+                classroom_url_fragment,
+                topic_url_fragment,
+                _,
+                _
+            ) = self.request.path.split('/')
+            self.redirect(
+                '/learn/%s/%s/practice' % (
+                    classroom_url_fragment, topic_url_fragment
+                )
+            )
+            return
+        super().handle_exception(exception, unused_debug_mode)
+
 
 class PracticeSessionsPageDataHandler(base.BaseHandler):
     """Fetches relevant data for the practice sessions page."""


Test patch: