Skip to content

Fix TableFormula error message to show existing Y value#2778

Merged
PavelBal merged 6 commits intodevelopfrom
copilot/fix-error-message-when-adding-point
Feb 25, 2026
Merged

Fix TableFormula error message to show existing Y value#2778
PavelBal merged 6 commits intodevelopfrom
copilot/fix-error-message-when-adding-point

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

When adding a point with a duplicate X coordinate but different Y value, TableFormula.AddPoint showed the attempted Y value in the error message instead of the existing Y value.

Example:

tableFormula.AddPoint(0, 0);   // Add initial point
tableFormula.AddPoint(0, 1);   // Attempt to add duplicate X
// Before: "A point for x=0 was already added with y=1"  ← wrong, shows new value
// After:  "A point for x=0 was already added with y=0"  ← correct, shows existing value

Changes:

  • TableFormula.cs: Pass existingPoint instead of point to the existing exception constructor
  • TableFormulaSpecs.cs: Add test verifying error message contains existing Y value
Original prompt

This section details on the original issue you should resolve

<issue_title>TableFormula: misleading error message when adding a point with existing x-value</issue_title>
<issue_description>If I try to add a point to the table formula in R, and the point with the same x (but a different y) value already exists in the table, I get the message A point for x=xValue was already added with y=newYValue:

tableParam$formula
TableFormula: 
  isTable: TRUE
  XDimension: Time
  UseDerivedValues: FALSE
  x= 0, y= 0, restartSolver= FALSE
  x= 60, y= 1, restartSolver= FALSE
  x= 120, y= 2, restartSolver= FALSE
  x= 180, y= 3, restartSolver= FALSE

tableParam$formula$addPoints(c(0, 1, 2), c(1, 5, 6))
Error in rClr::clrCall(self$ref, "AddPoint", xValues[i], yValues[i]) : 
  Type:    OSPSuite.Core.Domain.ValuePointAlreadyExistsForPointException
Message: A point for x=0 was already added with y=1
Method:  Int32 AddPoint(OSPSuite.Core.Domain.Formulas.ValuePoint)
Stack trace:
   bei OSPSuite.Core.Domain.Formulas.TableFormula.AddPoint(ValuePoint point)
   bei OSPSuite.Core.Domain.Formulas.TableFormula.AddPoint(Double x, Double y)

However this is wrong, as the point for x=1 was added with y = 0 and not y = 1.</issue_description>

<agent_instructions>The error is thrown in OSPSuite.Core.Domain.Formulas.TableFormula.AddPoint and must be changed there</agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits February 24, 2026 18:01
Co-authored-by: PavelBal <25903040+PavelBal@users.noreply.github.com>
Co-authored-by: PavelBal <25903040+PavelBal@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix misleading error message for existing x-value in TableFormula Fix TableFormula error message to show existing Y value Feb 24, 2026
Copilot AI requested a review from PavelBal February 24, 2026 18:04
@PavelBal PavelBal marked this pull request as ready for review February 24, 2026 18:17
return index;

throw new ValuePointAlreadyExistsForPointException(point);
throw new ValuePointAlreadyExistsForPointException(point.X, existingPoint.Y);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot just call the existing constructor with existingPoint. Remove the additional constructor that was added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 2d5ce04. Removed the new constructor overload and now calling the existing constructor with existingPoint instead.

…rload

Co-authored-by: rwmcintosh <261477+rwmcintosh@users.noreply.github.com>
@PavelBal PavelBal merged commit 3ea12c5 into develop Feb 25, 2026
5 checks passed
@PavelBal PavelBal deleted the copilot/fix-error-message-when-adding-point branch February 25, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TableFormula: misleading error message when adding a point with existing x-value

4 participants