diff --git a/client/src/app/core/repositories/motions/motion-repository.service.ts b/client/src/app/core/repositories/motions/motion-repository.service.ts
index 610785404..2730d5f7a 100644
--- a/client/src/app/core/repositories/motions/motion-repository.service.ts
+++ b/client/src/app/core/repositories/motions/motion-repository.service.ts
@@ -336,13 +336,18 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo
const changeRecos = viewMotion.changeRecommendations.filter(changeReco =>
changeReco.showInFinalView()
);
- return this.getAmendmentParagraphLines(
- viewMotion,
- this.motionLineLength,
- ChangeRecoMode.Changed,
- changeRecos,
- false
- );
+ try {
+ return this.getAmendmentParagraphLines(
+ viewMotion,
+ this.motionLineLength,
+ ChangeRecoMode.Changed,
+ changeRecos,
+ false
+ );
+ } catch (e) {
+ // Inconsistency between motion and amendment -> the best we can do is not to fail completely
+ return [];
+ }
} else {
return [];
}
@@ -810,6 +815,13 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo
let paragraph: string;
let paragraphHasChanges;
+ if (baseParagraphs[paraNo] === undefined) {
+ const msg =
+ 'Inconsistent data. An amendment is probably referring to a non-existant line number. ' +
+ 'You can back up its content when editing it and delete it afterwards.';
+ return '' + msg + '';
+ }
+
if (newText === null) {
paragraph = baseParagraphs[paraNo];
paragraphHasChanges = false;
@@ -855,6 +867,7 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo
* @param {ViewMotionChangeRecommendation[]} changeRecommendations
* @param {boolean} includeUnchanged
* @returns {DiffLinesInParagraph}
+ * @throws Error
*/
public getAmendmentParagraphLines(
amendment: ViewMotion,
@@ -876,7 +889,11 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo
return amendmentParagraphs
?.map(
(newText: string, paraNo: number): DiffLinesInParagraph => {
- if (newText !== null) {
+ if (baseParagraphs[paraNo] === undefined) {
+ throw new Error(
+ 'Inconsistent data. An amendment is probably referring to a non-existant line number.'
+ );
+ } else if (newText !== null) {
return this.diff.getAmendmentParagraphsLines(
paraNo,
baseParagraphs[paraNo],
@@ -950,6 +967,12 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo
if (newText === null) {
return null;
}
+ if (baseParagraphs[paraNo] === undefined) {
+ console.error(
+ 'Inconsistent data. An amendment is probably referring to a non-existant line number.'
+ );
+ return null;
+ }
const origText = baseParagraphs[paraNo],
diff = this.diff.diff(origText, newText),
@@ -990,6 +1013,9 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo
return (amendment.amendment_paragraphs || []).map((newText: string, paraNo: number): string => {
const origText = baseParagraphs[paraNo];
+ if (origText === undefined) {
+ throw new Error('Inconsistent data. An amendment is probably referring to a non-existant line number.');
+ }
if (newText === null) {
return origText;
diff --git a/client/src/app/core/ui-services/diff.service.ts b/client/src/app/core/ui-services/diff.service.ts
index 429a671e2..fcac55fcd 100644
--- a/client/src/app/core/ui-services/diff.service.ts
+++ b/client/src/app/core/ui-services/diff.service.ts
@@ -2238,7 +2238,8 @@ export class DiffService {
// That's a pretty serious inconsistency that should not happen at all,
// we're just doing some basic damage control here.
const msg =
- 'Inconsistent data. A change recommendation is probably referring to a non-existant line number.';
+ 'Inconsistent data. A change recommendation or amendment is probably referring to a non-existant line number. ' +
+ 'If it is an amendment, you can back up its content when editing it and delete it afterwards';
return '' + msg + '';
}
@@ -2299,7 +2300,7 @@ export class DiffService {
// That's a pretty serious inconsistency that should not happen at all,
// we're just doing some basic damage control here.
const msg =
- 'Inconsistent data. A change recommendation is probably referring to a non-existant line number.';
+ 'Inconsistent data. A change recommendation or amendment is probably referring to a non-existant line number.';
return '' + msg + '';
}
diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.ts b/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.ts
index 0fd73e919..3b2484211 100644
--- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.ts
+++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.ts
@@ -140,9 +140,14 @@ export class MotionDetailDiffComponent extends BaseViewComponentDirective implem
let baseText: LineNumberedString;
if (this.motion.isParagraphBasedAmendment()) {
- baseText = this.motionRepo
- .getAllAmendmentParagraphsWithOriginalLineNumbers(this.motion, this.lineLength, true)
- .join('\n');
+ try {
+ baseText = this.motionRepo
+ .getAllAmendmentParagraphsWithOriginalLineNumbers(this.motion, this.lineLength, true)
+ .join('\n');
+ } catch (e) {
+ console.error(e);
+ return '';
+ }
} else {
baseText = this.lineNumbering.insertLineNumbers(this.motion.text, this.lineLength);
}
@@ -184,9 +189,14 @@ export class MotionDetailDiffComponent extends BaseViewComponentDirective implem
}
let baseText: LineNumberedString;
if (this.motion.isParagraphBasedAmendment()) {
- baseText = this.motionRepo
- .getAllAmendmentParagraphsWithOriginalLineNumbers(this.motion, this.lineLength, true)
- .join('\n');
+ try {
+ baseText = this.motionRepo
+ .getAllAmendmentParagraphsWithOriginalLineNumbers(this.motion, this.lineLength, true)
+ .join('\n');
+ } catch (e) {
+ console.error(e);
+ return '';
+ }
} else {
baseText = this.lineNumbering.insertLineNumbers(this.motion.text, this.lineLength);
}
diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html
index 8dbac8f8d..173448648 100644
--- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html
+++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html
@@ -769,6 +769,10 @@
{{ 'This field is required.' | translate }}
+