TypeError: Cannot read properties of undefined (reading 'replace')
This error occurred recently in production:
TypeError: Cannot read properties of undefined (reading 'replace')
at c.transform (format-rte-preview.pipe.ts:35:17)
at an.getTranslationSuggestionHeading (contributions-and-review.component.ts:255:38)
at contributions-and-review.component.ts:231:23
at Array.forEach (<anonymous>)
at an.getTranslationContributionsSummary (contributions-and-review.component.ts:216:44)
at an.getContributionSummaries (contributions-and-review.component.ts:412:19)
at contributions-and-review.component.ts:498:34
at e.invoke (zone.js:386:30)
at Object.onInvoke (core.js:28580:33)
at e.invoke (zone.js:385:36)
Where did the error occur? Add the page the error occurred on.
Contributor dashboard page.
Frequency of occurrence Add details about how many times the error occurred within a given time period (e.g. the last week, the last 30 days, etc.). This helps issue triagers establish severity.
1 time in 4 days.
General instructions for contributors In general, the procedure for fixing 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.
- Based on your hypothesis, determine a list of steps that reliably reproduce the issue (or confirm any repro instructions that have been provided). For example, if your hypothesis is that the issue arises due to a delay in a response from the backend server, try to change the code so that the backend server always has a delay, and see if the error then shows up 100% of the time on your local machine.
- NOTE: See this comment for repro instructions (thanks @Ash-2k3 !)
- Explain your proposed fix, the logic behind it, and any other findings/context you have on this thread. You can also link to a debugging doc if you prefer.
- Get your approach validated by an Oppia team member.
- Make a PR that fixes the issue.
Additionally, see https://github.com/oppia/oppia/wiki/Contributor-dashboard for how to get started for developing for the contributor dashboard.
Hi @sagangwee, thanks for proposing this as a good first issue. I am removing the label for now and looping in @DubeySandeep to approve the label. It will be added back if approved. Thanks!
@DubeySandeep I would like to work on this. Could you please assign me this?
@aakankshabhende My apologies for the oversight. I initially labeled this as a "good first issue", but upon further examination, it seems to be a server error that requires in-depth debugging. Currently, we're unsure about the steps to reproduce this error, making it challenging to estimate the workload. To ensure that new contributors have a smooth start, I've removed the "good-first-issue" tag from this.
I recommend considering this issue instead: https://github.com/oppia/oppia/issues/17351
If you're interested in tackling that one, please indicate on the issue thread. Additionally, feel free to ask any questions related to it.
From the error snippet, it looks like the suggestion's translation (suggestion.change.translation_html) is undefined.
@DubeySandeep I would like to work on this issue once we get some clarity on this but till then could you please assign me the issue #17351
This issue occurs on the server about 1 time in a day.
This error is reproducible in local server for translations with rule inputs.
@Ash-2k3 Would you mind providing full repro instructions if possible? That would be pretty useful for server errors in general -- it converts the issue to a "normal" one.
Thanks!
Repro instructions
We need two different accounts, one to submit translation suggestion and other one to review it. (Note that both accounts need to have translation review rights, as only translation reviewers can submit translations for rule inputs. For more details on this, refer :https://github.com/oppia/oppia/issues/12959 )
Steps to reproduce:
- Log in as an admin
- Go to the /admin page under the "Roles" tab, and give yourself the following roles:
- Curriculum Admin
- Translation Admin
- In activities tab of admin page, click on load date for
Load dummy new structures data (only curriculum admins) - Go to url /contributor-dashboard-admin and give both the accounts review translation rights in the Akan language.
- Go to the contributor dashboard page under the "Translate Text" tab, and submit suggestions in Akan language for the listed opportunity titled as "What are Place Values ?" (This exploration has the content cards for rule inputs ).
- Log in with the second account
- (While doing step 7 make sure you have your browser console toggled on) Go to the contributor dashboard page under the "Review Translations" tab, and click on the opportunity listed. Finally, click on the listed suggestion. Observe the browser console errors and terminal errors (switch back to your terminal to check this).
Browser Console:
logger.service.ts:59 this.rteString.replace is not a function
error @ logger.service.ts:59
handleError @ app-error-handler.ts:85
eval @ core.js:30009
ZoneDelegate.invoke @ zone.js:390
Zone.run @ zone.js:147
runOutsideAngular @ core.js:28951
tick @ core.js:30009
eval @ core.js:29878
ZoneDelegate.invoke @ zone.js:390
onInvoke @ core.js:29022
ZoneDelegate.invoke @ zone.js:389
Zone.run @ zone.js:147
run @ core.js:28906
next @ core.js:29877
SafeSubscriber.__tryOrUnsub @ Subscriber.js:201
SafeSubscriber.next @ Subscriber.js:139
Subscriber._next @ Subscriber.js:85
Subscriber.next @ Subscriber.js:62
Subject.next @ Subject.js:57
emit @ core.js:26382
checkStable @ core.js:28959
onLeave @ core.js:29072
onInvokeTask @ core.js:29016
ZoneDelegate.invokeTask @ zone.js:424
Zone.runTask @ zone.js:192
ZoneTask.invokeTask @ zone.js:507
invokeTask @ zone.js:1675
globalZoneAwareCallback @ zone.js:1701
Show 26 more frames
Show less
TranslationSuggestionReviewModalComponent.html:52 ERROR TypeError: this.rteString.replace is not a function
at RteOutputDisplayComponent._updateNode (rte-output-display.component.ts:60:41)
at RteOutputDisplayComponent.ngOnChanges (rte-output-display.component.ts:161:18)
at checkAndUpdateDirectiveInline (core.js:25111:19)
at checkAndUpdateNodeInline (core.js:32301:20)
at checkAndUpdateNode (core.js:32263:16)
at debugCheckAndUpdateNode (core.js:32890:21)
at debugCheckDirectivesFn (core.js:32854:13)
at Object.eval [as updateDirectives] (TranslationSuggestionReviewModalComponent.html:52:11)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:32850:21)
at checkAndUpdateView (core.js:32245:14)
View_TranslationSuggestionReviewModalComponent_7 @ TranslationSuggestionReviewModalComponent.html:52
logError @ core.js:33039
handleError @ core.js:6700
handleError @ app-error-handler.ts:86
eval @ core.js:30009
ZoneDelegate.invoke @ zone.js:390
Zone.run @ zone.js:147
runOutsideAngular @ core.js:28951
tick @ core.js:30009
eval @ core.js:29878
ZoneDelegate.invoke @ zone.js:390
onInvoke @ core.js:29022
ZoneDelegate.invoke @ zone.js:389
Zone.run @ zone.js:147
run @ core.js:28906
next @ core.js:29877
SafeSubscriber.__tryOrUnsub @ Subscriber.js:201
SafeSubscriber.next @ Subscriber.js:139
Subscriber.next @ Subscriber.js:85
Subscriber.next @ Subscriber.js:62
Subject.next @ Subject.js:57
emit @ core.js:26382
checkStable @ core.js:28959
onLeave @ core.js:29072
onInvokeTask @ core.js:29016
ZoneDelegate.invokeTask @ zone.js:424
Zone.runTask @ zone.js:192
ZoneTask.invokeTask @ zone.js:507
invokeTask @ zone.js:1675
globalZoneAwareCallback @ zone.js:1701
Show 28 more frames
Show less
TranslationSuggestionReviewModalComponent.html:52 ERROR CONTEXT DebugContext {view: {…}, nodeIndex: 1, nodeDef: {…}, elDef: {…}, elView: {…}}
View_TranslationSuggestionReviewModalComponent_7 @ TranslationSuggestionReviewModalComponent.html:52
logError @ core.js:33039
handleError @ core.js:6705
handleError @ app-error-handler.ts:86
eval @ core.js:30009
ZoneDelegate.invoke @ zone.js:390
Zone.run @ zone.js:147
runOutsideAngular @ core.js:28951
tick @ core.js:30009
eval @ core.js:29878
ZoneDelegate.invoke @ zone.js:390
onInvoke @ core.js:29022
ZoneDelegate.invoke @ zone.js:389
Zone.run @ zone.js:147
run @ core.js:28906
next @ core.js:29877
SafeSubscriber.__tryOrUnsub @ Subscriber.js:201
SafeSubscriber.next @ Subscriber.js:139
Subscriber._next @ Subscriber.js:85
Subscriber.next @ Subscriber.js:62
Subject.next @ Subject.js:57
emit @ core.js:26382
checkStable @ core.js:28959
onLeave @ core.js:29072
onInvokeTask @ core.js:29016
ZoneDelegate.invokeTask @ zone.js:424
Zone.runTask @ zone.js:192
ZoneTask.invokeTask @ zone.js:507
invokeTask @ zone.js:1675
globalZoneAwareCallback @ zone.js:1701
Show 28 more frames
Show less
logger.service.ts:59 this.rteString.replace is not a function
error @ logger.service.ts:59
handleError @ app-error-handler.ts:85
eval @ core.js:30009
ZoneDelegate.invoke @ zone.js:390
Zone.run @ zone.js:147
runOutsideAngular @ core.js:28951
tick @ core.js:30009
eval @ core.js:29878
ZoneDelegate.invoke @ zone.js:390
onInvoke @ core.js:29022
ZoneDelegate.invoke @ zone.js:389
Zone.run @ zone.js:147
run @ core.js:28906
next @ core.js:29877
SafeSubscriber.__tryOrUnsub @ Subscriber.js:201
SafeSubscriber.next @ Subscriber.js:139
Subscriber._next @ Subscriber.js:85
Subscriber.next @ Subscriber.js:62
Subject.next @ Subject.js:57
emit @ core.js:26382
checkStable @ core.js:28959
onHasTask @ core.js:29039
ZoneDelegate.hasTask @ zone.js:445
ZoneDelegate._updateTaskCount @ zone.js:466
Zone._updateTaskCount @ zone.js:288
Zone.runTask @ zone.js:209
drainMicroTaskQueue @ zone.js:605
ZoneTask.invokeTask @ zone.js:511
invokeTask @ zone.js:1675
globalZoneAwareCallback @ zone.js:1701
Show 28 more frames
Show less
TranslationSuggestionReviewModalComponent.html:52 ERROR TypeError: this.rteString.replace is not a function
at RteOutputDisplayComponent._updateNode (rte-output-display.component.ts:60:41)
at RteOutputDisplayComponent.ngAfterViewInit (rte-output-display.component.ts:116:14)
at callProviderLifecycles (core.js:25427:18)
at callElementProvidersLifecycles (core.js:25401:13)
at callLifecycleHooksChildrenFirst (core.js:25391:29)
at checkAndUpdateView (core.js:32254:5)
at callViewAction (core.js:32486:21)
at execEmbeddedViewsAction (core.js:32449:17)
at checkAndUpdateView (core.js:32246:5)
at callViewAction (core.js:32486:21)
View_TranslationSuggestionReviewModalComponent_7 @ TranslationSuggestionReviewModalComponent.html:52
logError @ core.js:33039
handleError @ core.js:6700
handleError @ app-error-handler.ts:86
eval @ core.js:30009
ZoneDelegate.invoke @ zone.js:390
Zone.run @ zone.js:147
runOutsideAngular @ core.js:28951
tick @ core.js:30009
eval @ core.js:29878
ZoneDelegate.invoke @ zone.js:390
onInvoke @ core.js:29022
ZoneDelegate.invoke @ zone.js:389
Zone.run @ zone.js:147
run @ core.js:28906
next @ core.js:29877
SafeSubscriber.__tryOrUnsub @ Subscriber.js:201
SafeSubscriber.next @ Subscriber.js:139
Subscriber._next @ Subscriber.js:85
Subscriber.next @ Subscriber.js:62
Subject.next @ Subject.js:57
emit @ core.js:26382
checkStable @ core.js:28959
onHasTask @ core.js:29039
ZoneDelegate.hasTask @ zone.js:445
ZoneDelegate._updateTaskCount @ zone.js:466
Zone.updateTaskCount @ zone.js:288
Zone.runTask @ zone.js:209
drainMicroTaskQueue @ zone.js:605
ZoneTask.invokeTask @ zone.js:511
invokeTask @ zone.js:1675
globalZoneAwareCallback @ zone.js:1701
Show 30 more frames
Show less
TranslationSuggestionReviewModalComponent.html:52 ERROR CONTEXT DebugContext {view: {…}, nodeIndex: 1, nodeDef: {…}, elDef: {…}, elView: {…}}
View_TranslationSuggestionReviewModalComponent_7 @ TranslationSuggestionReviewModalComponent.html:52
logError @ core.js:33039
handleError @ core.js:6705
handleError @ app-error-handler.ts:86
eval @ core.js:30009
ZoneDelegate.invoke @ zone.js:390
Zone.run @ zone.js:147
runOutsideAngular @ core.js:28951
tick @ core.js:30009
eval @ core.js:29878
ZoneDelegate.invoke @ zone.js:390
onInvoke @ core.js:29022
ZoneDelegate.invoke @ zone.js:389
Zone.run @ zone.js:147
run @ core.js:28906
next @ core.js:29877
SafeSubscriber.__tryOrUnsub @ Subscriber.js:201
SafeSubscriber.next @ Subscriber.js:139
Subscriber._next @ Subscriber.js:85
Subscriber.next @ Subscriber.js:62
Subject.next @ Subject.js:57
emit @ core.js:26382
checkStable @ core.js:28959
onHasTask @ core.js:29039
ZoneDelegate.hasTask @ zone.js:445
ZoneDelegate._updateTaskCount @ zone.js:466
Zone._updateTaskCount @ zone.js:288
Zone.runTask @ zone.js:209
drainMicroTaskQueue @ zone.js:605
ZoneTask.invokeTask @ zone.js:511
invokeTask @ zone.js:1675
globalZoneAwareCallback @ zone.js:1701
Show 30 more frames
Show less
logger.service.ts:59 Cannot read properties of undefined (reading 'elementRef')
error @ logger.service.ts:59
handleError @ app-error-handler.ts:85
next @ core.js:29625
SafeSubscriber.__tryOrUnsub @ Subscriber.js:201
SafeSubscriber.next @ Subscriber.js:139
Subscriber._next @ Subscriber.js:85
Subscriber.next @ Subscriber.js:62
Subject.next @ Subject.js:57
emit @ core.js:26382
eval @ core.js:29048
ZoneDelegate.invoke @ zone.js:390
Zone.run @ zone.js:147
runOutsideAngular @ core.js:28951
onHandleError @ core.js:29048
ZoneDelegate.handleError @ zone.js:394
Zone.runTask @ zone.js:195
ZoneTask.invokeTask @ zone.js:507
ZoneTask.invoke @ zone.js:496
timer @ zone.js:3038
setTimeout (async)
scheduleTask @ zone.js:3059
ZoneDelegate.scheduleTask @ zone.js:411
onScheduleTask @ zone.js:298
ZoneDelegate.scheduleTask @ zone.js:404
Zone.scheduleTask @ zone.js:235
Zone.scheduleMacroTask @ zone.js:258
scheduleMacroTaskWithCurrentZone @ zone.js:1187
eval @ zone.js:3072
proto.
Terminal error:
ERROR:root:Frontend error: this.rteString.replace is not a function
at URL: http://localhost:8181/contributor-dashboard
INFO 2024-03-12 16:13:29,107 module.py:883] default: "POST /frontend_errors HTTP/1.1" 200 72 ERROR:root:Frontend error: this.rteString.replace is not a function
at URL: http://localhost:8181/contributor-dashboard
INFO 2024-03-12 16:13:29,211 module.py:883] default: "POST /frontend_errors HTTP/1.1" 200 72 ERROR:root:Frontend error: Cannot read properties of undefined (reading 'elementRef')
at URL: http://localhost:8181/contributor-dashboard
INFO 2024-03-12 16:13:29,464 module.py:883] default: "POST /frontend_errors HTTP/1.1" 200 72 ERROR:root:Frontend error: Cannot read properties of undefined (reading 'elementRef')
at URL: http://localhost:8181/contributor-dashboard
Hmm upon comparing the logs mentioned in the issue description and the one I found, I am not sure if they are the same ? I don't think this.rteString.replace is not a function is the same as Cannot read properties of undefined (reading 'replace'). Maybe they are related ? @seanlip
@Ash-2k3 Not sure, needs investigation. It sounds like two issues:
- The first one suggests that this.rteString doesn't have a "replace" method. But to understand what's going on here you'll need to know what the type of this.rteString is. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_function
- The second one suggests that this.rteString is undefined.
I think it's worth fixing what you can repro anyway, since there seem to be several issues with how this.rteString is being handled. Maybe the stacktrace info can also help?
Also @Ash-2k3 I don't think https://github.com/oppia/oppia/issues/18924#issuecomment-1992044276 suffices as instructions. Please give step-by-step repro instructions (e.g. step 1: log in as user XYZ and go to URL ABC, etc.), thanks.
@seanlip, Thanks, I have updated my comment, lmk if anything else is needed.
Thanks @Ash-2k3, that looks much better! I made some small edits, it should be good to use now.
@Ash-2k3 Also just to check, I think you've been making some fixes related to rule input translations. Do any of those fix this issue?
Nope, I don't think so. I only fixed issue related to calculation of html strings for rule inputs (We didn't consider argument to be of type list of strings).
The error has occurred once on the test server in the release version 3-3-9 with the following logs:
Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'replace')
TypeError: Cannot read properties of undefined (reading 'replace')
at c.transform (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8a266c83a4158936980c.bundle.js:3815:141890)
at _n.getTranslationSuggestionHeading (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8a266c83a4158936980c.bundle.js:3982:229388)
at https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8a266c83a4158936980c.bundle.js:3982:228502
at Array.forEach (<anonymous>)
at _n.getTranslationContributionsSummary (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8a266c83a4158936980c.bundle.js:3982:228291)
at _n.getContributionSummaries (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8a266c83a4158936980c.bundle.js:3982:232247)
at https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8a266c83a4158936980c.bundle.js:3982:234606
at e.invoke (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8a266c83a4158936980c.bundle.js:3439:7175)
at Object.onInvoke (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8a266c83a4158936980c.bundle.js:1377:1773)
at e.invoke (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8a266c83a4158936980c.bundle.js:3439:7115)
at URL: https://www.oppiatestserver.org/contributor-dashboard
The error occurred once on test-server since 9th Oct 2024 with version 3.4.3 with the following logs:
Frontend error:
Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'replace')
TypeError: Cannot read properties of undefined (reading 'replace')
at c.transform (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8581188dd2bd56a10de1.bundle.js:3522:188511)
at Qt.getTranslationSuggestionHeading (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8581188dd2bd56a10de1.bundle.js:3652:204045)
at https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8581188dd2bd56a10de1.bundle.js:3652:203159
at Array.forEach (<anonymous>)
at Qt.getTranslationContributionsSummary (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8581188dd2bd56a10de1.bundle.js:3652:202948)
at Qt.getContributionSummaries (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8581188dd2bd56a10de1.bundle.js:3652:206904)
at https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8581188dd2bd56a10de1.bundle.js:3652:209263
at e.invoke (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8581188dd2bd56a10de1.bundle.js:3295:7175)
at Object.onInvoke (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8581188dd2bd56a10de1.bundle.js:1377:1773)
at e.invoke (https://www.oppiatestserver.org/build/webpack_bundles/contributor_dashboard.8581188dd2bd56a10de1.bundle.js:3295:7115)
at URL: https://www.oppiatestserver.org/contributor-dashboard