Compare commits

...

3 commits

Author SHA1 Message Date
9239eac78a
Fixing several function calls with no argument errors.
All checks were successful
continuous-integration/drone/push Build is passing
+ Functions max and min now throw an error if no arguments are provided.
+ Objects called now throw an error if no argument is provided.
+ Fixing tokenizer's seek error reporting system (leads to very rare types of errors).
+ Removing expression simplifications that could make the app freeze when no arguments are provided to a function.
2023-05-24 07:43:40 +02:00
35ce1c4824
Adding error handling for function argument errors. 2023-05-24 07:03:12 +02:00
75e70903f1
Fixing coloration in dark theme of autocomplete categories. 2023-05-24 06:47:34 +02:00
13 changed files with 136 additions and 19 deletions

View file

@ -1046,6 +1046,14 @@ Evaluated expression: %3</source>
Ausdruck analysiert: %3</translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="179"/>
<source>Error while attempting to draw %1 %2:
%3
Undoing last change.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>expression</name>
@ -1066,6 +1074,11 @@ Evaluated expression: %3</source>
Ausdruck analysiert: %3</translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="176"/>
<source>LogarithmPlotter - Drawing error</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>function</name>

View file

@ -1046,6 +1046,14 @@ Evaluated expression: %3</source>
Evaluated expression: %3</translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="179"/>
<source>Error while attempting to draw %1 %2:
%3
Undoing last change.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>expression</name>
@ -1066,6 +1074,11 @@ Evaluated expression: %3</source>
Evaluated expression: %3</translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="176"/>
<source>LogarithmPlotter - Drawing error</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>function</name>

View file

@ -991,6 +991,14 @@ These settings can be changed at any time from the &quot;Settings&quot; menu.</s
Evaluated expression: %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="179"/>
<source>Error while attempting to draw %1 %2:
%3
Undoing last change.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>expression</name>
@ -1008,6 +1016,11 @@ Evaluated expression: %3</source>
Evaluated expression: %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="176"/>
<source>LogarithmPlotter - Drawing error</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>function</name>

View file

@ -1055,6 +1055,14 @@ Evaluated expression: %3</source>
Formule analysée : %3</translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="179"/>
<source>Error while attempting to draw %1 %2:
%3
Undoing last change.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>expression</name>
@ -1075,6 +1083,11 @@ Evaluated expression: %3</source>
Formule analysée : %3</translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="176"/>
<source>LogarithmPlotter - Drawing error</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>function</name>

View file

@ -1046,6 +1046,14 @@ Evaluated expression: %3</source>
Kiértékelt kifejezés: %3</translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="179"/>
<source>Error while attempting to draw %1 %2:
%3
Undoing last change.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>expression</name>
@ -1066,6 +1074,11 @@ Evaluated expression: %3</source>
Kiértékelt kifejezés: %3</translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="176"/>
<source>LogarithmPlotter - Drawing error</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>function</name>

View file

@ -1043,6 +1043,14 @@ Disse innstillingene kan endres når som helst fra «Innstillinger»-menyen.</tr
Evaluated expression: %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="179"/>
<source>Error while attempting to draw %1 %2:
%3
Undoing last change.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>expression</name>
@ -1060,6 +1068,11 @@ Evaluated expression: %3</source>
Evaluated expression: %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="176"/>
<source>LogarithmPlotter - Drawing error</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>function</name>

View file

@ -991,6 +991,14 @@ These settings can be changed at any time from the &quot;Settings&quot; menu.</s
Evaluated expression: %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="179"/>
<source>Error while attempting to draw %1 %2:
%3
Undoing last change.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>expression</name>
@ -1008,6 +1016,11 @@ Evaluated expression: %3</source>
Evaluated expression: %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml" line="176"/>
<source>LogarithmPlotter - Drawing error</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>function</name>

View file

@ -16,7 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick
import QtQuick
import Qt.labs.platform as Native
import "js/objects.js" as Objects
import "js/utils.js" as Utils
import "js/mathlib.js" as MathLib
@ -170,6 +171,16 @@ Canvas {
Component.onCompleted: imageLoaders = {}
Native.MessageDialog {
id: drawingErrorDialog
title: qsTranslate("expression", "LogarithmPlotter - Drawing error")
text: ""
function showDialog(objType, objName, error) {
text = qsTranslate("error", "Error while attempting to draw %1 %2:\n%3\n\nUndoing last change.").arg(objType).arg(objName).arg(error)
open()
}
}
onPaint: function(rect) {
//console.log('Redrawing')
if(rect.width == canvas.width) { // Redraw full canvas
@ -183,7 +194,14 @@ Canvas {
for(var obj of Objects.currentObjects[objType]){
ctx.strokeStyle = obj.color
ctx.fillStyle = obj.color
if(obj.visible) obj.draw(canvas, ctx)
if(obj.visible)
try {
obj.draw(canvas, ctx)
} catch(e) {
// Drawing throws an error. Generally, it's due to a new modification (or the opening of a file)
drawingErrorDialog.showDialog(objType, obj.name, e.message)
history.undo()
}
}
}
ctx.lineWidth = 1

View file

@ -91,7 +91,7 @@ Repeater {
root.changed()
}
}
}
}
}

View file

@ -84,11 +84,12 @@ ListView {
Text {
leftPadding: 5
text: listFiltered.category
color: sysPalette.windowText
}
Rectangle {
height: 1
color: 'black'
color: 'gray'
width: parent.width
}
}

View file

@ -241,7 +241,10 @@ function evaluate(tokens, expr, values) {
nstack.push(f.apply(undefined, args));
} else if(f.execute) {
// Objects & expressions execution
nstack.push(f.execute.apply(f, args));
if(args.length >= 1)
nstack.push(f.execute.apply(f, args));
else
throw new Error(qsTranslate('error', 'In order to be executed, object %1 must have at least one argument.').arg(f))
} else {
throw new Error(qsTranslate('error', '%1 cannot be executed.').arg(f));
}
@ -1614,16 +1617,20 @@ function arrayIndex(array, index) {
function max(array) {
if (arguments.length === 1 && Array.isArray(array)) {
return Math.max.apply(Math, array);
} else {
} else if(arguments.length >= 1) {
return Math.max.apply(Math, arguments);
} else {
throw new EvalError(qsTranslate('error', 'Function %1 must have at least one argument.').arg('max'))
}
}
function min(array) {
if (arguments.length === 1 && Array.isArray(array)) {
return Math.min.apply(Math, array);
} else {
} else if(arguments.length >= 1) {
return Math.min.apply(Math, arguments);
} else {
throw new EvalError(qsTranslate('error', 'Function %1 must have at least one argument.').arg('min'))
}
}

View file

@ -36,7 +36,7 @@ class InputExpression {
if(!this.atEnd() && this.peek() == char) {
this.position++;
} else {
this.raise("Unexpected character " + peek() + ". Expected character " + char);
this.raise("Unexpected character " + this.peek() + ". Expected character " + char);
}
}

View file

@ -216,16 +216,16 @@ function simplifyExpression(str) {
}
],
// Simple simplifications
[/(\s|^|\()0(\.0+)? \* (\([^)(]+\))/g, '$10'],
[/(\s|^|\()0(\.0+)? \* ([^)(+-]+)/g, '$10'],
[/(\([^)(]\)) \* 0(\.0+)?(\s|$|\))/g, '0$3'],
[/([^)(+-]) \* 0(\.0+)?(\s|$|\))/g, '0$3'],
[/(\s|^|\()1(\.0+)? (\*|\/) /g, '$1'],
[/(\s|^|\()0(\.0+)? (\+|\-) /g, '$1'],
[/ (\*|\/) 1(\.0+)?(\s|$|\))/g, '$3'],
[/ (\+|\-) 0(\.0+)?(\s|$|\))/g, '$3'],
[/(^| |\() /g, '$1'],
[/ ($|\))/g, '$1'],
// [/(\s|^|\()0(\.0+)? \* (\([^)(]+\))/g, '$10'],
// [/(\s|^|\()0(\.0+)? \* ([^)(+-]+)/g, '$10'],
// [/(\([^)(]\)) \* 0(\.0+)?(\s|$|\))/g, '0$3'],
// [/([^)(+-]) \* 0(\.0+)?(\s|$|\))/g, '0$3'],
// [/(\s|^|\()1(\.0+)? (\*|\/) /g, '$1'],
// [/(\s|^|\()0(\.0+)? (\+|\-) /g, '$1'],
// [/ (\*|\/) 1(\.0+)?(\s|$|\))/g, '$3'],
// [/ (\+|\-) 0(\.0+)?(\s|$|\))/g, '$3'],
// [/(^| |\() /g, '$1'],
// [/ ($|\))/g, '$1'],
]
// Replacements
@ -271,7 +271,7 @@ function makeExpressionReadable(str) {
}]
]
str = simplifyExpression(str)
// str = simplifyExpression(str)
// Replacements
for(var replacement of replacements)
while(replacement[0].test(str))