Skip to content

Commit

Permalink
tons of changes to how the errors system works
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Wicenec committed Jul 8, 2024
1 parent a84a702 commit 3d29bdc
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 131 deletions.
12 changes: 6 additions & 6 deletions src/Eagle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2855,7 +2855,7 @@ export class Eagle {

// validate edge
const isValid: Errors.Validity = Edge.isValid(this,false, edge.getId(), edge.getSrcNodeKey(), edge.getSrcPortId(), edge.getDestNodeKey(), edge.getDestPortId(), edge.isLoopAware(), edge.isClosesLoop(), false, true, null);
if (isValid === Errors.Validity.Impossible || isValid === Errors.Validity.Invalid || isValid === Errors.Validity.Unknown){
if (isValid === Errors.Validity.Impossible || isValid === Errors.Validity.Error || isValid === Errors.Validity.Unknown){
Utils.showUserMessage("Error", "Invalid edge");
return;
}
Expand Down Expand Up @@ -2900,7 +2900,7 @@ export class Eagle {

// validate edge
const isValid: Errors.Validity = Edge.isValid(this,false, edge.getId(), edge.getSrcNodeKey(), edge.getSrcPortId(), edge.getDestNodeKey(), edge.getDestPortId(), edge.isLoopAware(), edge.isClosesLoop(), false, true, null);
if (isValid === Errors.Validity.Impossible || isValid === Errors.Validity.Invalid || isValid === Errors.Validity.Unknown){
if (isValid === Errors.Validity.Impossible || isValid === Errors.Validity.Error || isValid === Errors.Validity.Unknown){
Utils.showUserMessage("Error", "Invalid edge");
return;
}
Expand Down Expand Up @@ -4566,10 +4566,10 @@ export class Eagle {
}

checkGraph = (): void => {
const checkResult = Utils.checkGraph(this);

this.graphWarnings(checkResult.warnings);
this.graphErrors(checkResult.errors);
Utils.checkGraph(this);//validate the graph
const graphErrors = Utils.gatherGraphErrors() //gather all the errors from all of the components
this.graphWarnings(graphErrors.warnings);
this.graphErrors(graphErrors.errors);
};

showGraphErrors = (): void => {
Expand Down
24 changes: 12 additions & 12 deletions src/Edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,18 @@ export class Edge {

// check that we are not connecting a Data component to a Data component, that is not supported
if (sourceNode.getCategoryType() === Category.Type.Data && destinationNode.getCategoryType() === Category.Type.Data){
Edge.isValidLog(edgeId, Errors.Validity.Invalid, Errors.Show("Data nodes may not be connected directly to other Data nodes", function(){Utils.showEdge(eagle, edgeId);}), showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, Errors.Show("Data nodes may not be connected directly to other Data nodes", function(){Utils.showEdge(eagle, edgeId);}), showNotification, showConsole, errorsWarnings);
}

// if source node or destination node is a construct, then something is wrong, constructs should not have ports
if (sourceNode.getCategoryType() === Category.Type.Construct){
const issue: Errors.Issue = Errors.ShowFix("Edge (" + edgeId + ") cannot have a source node (" + sourceNode.getName() + ") that is a construct", function(){Utils.showEdge(eagle, edgeId)}, function(){Utils.fixMoveEdgeToEmbeddedApplication(eagle, edgeId)}, "Move edge to embedded application");
Edge.isValidLog(edgeId, Errors.Validity.Invalid, issue, showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, issue, showNotification, showConsole, errorsWarnings);
}

if (destinationNode.getCategoryType() === Category.Type.Construct){
const issue: Errors.Issue = Errors.ShowFix("Edge (" + edgeId + ") cannot have a destination node (" + destinationNode.getName() + ") that is a construct", function(){Utils.showEdge(eagle, edgeId)}, function(){Utils.fixMoveEdgeToEmbeddedApplication(eagle, edgeId)}, "Move edge to embedded application");
Edge.isValidLog(edgeId, Errors.Validity.Invalid, issue, showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, issue, showNotification, showConsole, errorsWarnings);
}

// if source node is a memory, and destination is a BashShellApp, OR
Expand All @@ -349,7 +349,7 @@ export class Edge {
if ((sourceNode.getCategory() === Category.Memory && destinationNode.getCategory() === Category.BashShellApp) ||
(sourceNode.getCategory() === Category.Memory && destinationNode.isGroup() && destinationNode.getInputApplication() !== undefined && destinationNode.hasInputApplication() && destinationNode.getInputApplication().getCategory() === Category.BashShellApp)){
const issue: Errors.Issue = Errors.ShowFix("output from Memory Node cannot be input into a BashShellApp or input into a Group Node with a BashShellApp inputApplicationType", function(){Utils.showNode(eagle, sourceNode.getId())}, function(){Utils.fixNodeCategory(eagle, sourceNode, Category.File, Category.Type.Data)}, "Change data component type to File");
Edge.isValidLog(edgeId, Errors.Validity.Invalid, issue, showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, issue, showNotification, showConsole, errorsWarnings);
}

const sourcePort : Field = sourceNode.findFieldById(sourcePortId);
Expand Down Expand Up @@ -392,7 +392,7 @@ export class Edge {
if (sourcePort !== null && destinationPort !== null){
// check that source and destination port are both event, or both not event
if ((sourcePort.getIsEvent() && !destinationPort.getIsEvent()) || (!sourcePort.getIsEvent() && destinationPort.getIsEvent())){
Edge.isValidLog(edgeId, Errors.Validity.Invalid, Errors.Show("Source port and destination port are mix of event and non-event ports", function(){Utils.showEdge(eagle, edgeId);}), showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, Errors.Show("Source port and destination port are mix of event and non-event ports", function(){Utils.showEdge(eagle, edgeId);}), showNotification, showConsole, errorsWarnings);
}
}

Expand Down Expand Up @@ -422,7 +422,7 @@ export class Edge {
// abort if source port and destination port have different data types
if (!Utils.portsMatch(sourcePort, destinationPort)){
const x = Errors.ShowFix("Source and destination ports don't match data types: sourcePort (" + sourcePort.getDisplayText() + ":" + sourcePort.getType() + ") destinationPort (" + destinationPort.getDisplayText() + ":" + destinationPort.getType() + ")", function(){Utils.showEdge(eagle, edgeId);}, function(){Utils.fixPortType(eagle, sourcePort, destinationPort);}, "Overwrite destination port type with source port type");
Edge.isValidLog(edgeId, Errors.Validity.Invalid, x, showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, x, showNotification, showConsole, errorsWarnings);
}
}

Expand Down Expand Up @@ -450,7 +450,7 @@ export class Edge {

if ( isSrcMatch && isDestMatch && edge.getId() !== edgeId){
const x = Errors.ShowFix("Edge is a duplicate. Another edge with the same source port and destination port already exists", function(){Utils.showEdge(eagle, edgeId);}, function(){Utils.fixDeleteEdge(eagle, edgeId);}, "Delete edge");
Edge.isValidLog(edgeId, Errors.Validity.Invalid, x, showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, x, showNotification, showConsole, errorsWarnings);
}
}

Expand All @@ -462,22 +462,22 @@ export class Edge {
if (closesLoop){
if (!sourceNode.isData()){
const x = Errors.Show("Closes Loop Edge (" + edgeId + ") does not start from a Data component.", function(){Utils.showEdge(eagle, edgeId);});
Edge.isValidLog(edgeId, Errors.Validity.Invalid, x, showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, x, showNotification, showConsole, errorsWarnings);
}

if (!destinationNode.isApplication()){
const x = Errors.Show("Closes Loop Edge (" + edgeId + ") does not end at an Application component.", function(){Utils.showEdge(eagle, edgeId);});
Edge.isValidLog(edgeId, Errors.Validity.Invalid, x, showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, x, showNotification, showConsole, errorsWarnings);
}

if (!sourceNode.hasFieldWithDisplayText(Daliuge.FieldName.GROUP_END) || !Utils.asBool(sourceNode.getFieldByDisplayText(Daliuge.FieldName.GROUP_END).getValue())){
const x = Errors.ShowFix("'Closes Loop' Edge (" + edgeId + ") start node (" + sourceNode.getName() + ") does not have 'group_end' set to true.", function(){Utils.showEdge(eagle, edgeId);}, function(){Utils.fixFieldValue(eagle, sourceNode, Daliuge.groupEndField, "true")}, "Set 'group_end' to true");
Edge.isValidLog(edgeId, Errors.Validity.Invalid, x, showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, x, showNotification, showConsole, errorsWarnings);
}

if (!destinationNode.hasFieldWithDisplayText(Daliuge.FieldName.GROUP_START) || !Utils.asBool(destinationNode.getFieldByDisplayText(Daliuge.FieldName.GROUP_START).getValue())){
const x = Errors.ShowFix("'Closes Loop' Edge (" + edgeId + ") end node (" + destinationNode.getName() + ") does not have 'group_start' set to true.", function(){Utils.showEdge(eagle, edgeId);}, function(){Utils.fixFieldValue(eagle, destinationNode, Daliuge.groupStartField, "true")}, "Set 'group_start' to true");
Edge.isValidLog(edgeId, Errors.Validity.Invalid, x, showNotification, showConsole, errorsWarnings);
Edge.isValidLog(edgeId, Errors.Validity.Error, x, showNotification, showConsole, errorsWarnings);
}
}

Expand All @@ -504,7 +504,7 @@ export class Edge {
title = "Edge Impossible";
type = "danger";
break;
case Errors.Validity.Invalid:
case Errors.Validity.Error:
title = "Edge Invalid";
type = "danger";
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export namespace Errors
export enum Validity {
Unknown = "Unknown", // validity of the edge is unknown
Impossible = "Impossible", // never useful or valid
Invalid = "Invalid", // invalid, but possibly useful for expert users? change to error
Error = "Error", // invalid, but possibly useful for expert users? change to error
Warning = "Warning", // valid, but some issue that the user should be aware of
Fixable = "Fixable", // there is an issue with the connection but for drawing edges eagle will fix this for you
Valid = "Valid" // fine
Expand Down
40 changes: 28 additions & 12 deletions src/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class Field {
private inputAngle : number;
private outputAngle : number;

private errorsArray : {issue:Errors.Issue, validity:Errors.Validity}[]
private errorsWarnings : ko.Observable<Errors.ErrorsWarnings>;

constructor(id: string, displayText: string, value: string, defaultValue: string, description: string, readonly: boolean, type: string, precious: boolean, options: string[], positional: boolean, parameterType: Daliuge.FieldType, usage: Daliuge.FieldUsage, keyAttribute: boolean){
Expand Down Expand Up @@ -73,6 +74,7 @@ export class Field {
this.inputAngle = 0;
this.outputAngle = 0;

this.errorsArray = [];
this.errorsWarnings = ko.observable({warnings: [], errors: []});
}

Expand Down Expand Up @@ -348,6 +350,10 @@ export class Field {
return this.errorsWarnings();
}

getErrors = (): {issue:Errors.Issue, validity:Errors.Validity}[] => {
return this.errorsArray;
}

addErrorsWarnings(issue:Errors.Issue, issueType:string) : void {
if(issueType === 'error'){
this.errorsWarnings().errors.push(issue)
Expand Down Expand Up @@ -803,7 +809,7 @@ export class Field {

static isValid(node:Node, field:Field, selectedLocation:Eagle.FileType, fieldIndex:number){
const eagle = Eagle.getInstance()
const errorsWarnings : Errors.ErrorsWarnings = {warnings: [], errors: []};
// const errorsWarnings : Errors.ErrorsWarnings = {warnings: [], errors: []};

//checks for input ports
if(field.isInputPort()){
Expand All @@ -827,7 +833,9 @@ export class Field {
issue = Errors.ShowFix("Node " + node.getKey() + " (" + parentNode.getName() + ") has output application (" + node.getName() + ") with input port (" + field.getDisplayText() + ") whose type is not specified", function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixFieldType(eagle, field)}, "");
}
}
errorsWarnings.warnings.push(issue);

field.errorsArray.push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}


Expand Down Expand Up @@ -855,7 +863,8 @@ export class Field {
issue = Errors.ShowFix("Node " + node.getKey() + " (" + parentNode.getName() + ") has output application (" + node.getName() + ") with output port (" + field.getDisplayText() + ") whose type is not specified", function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixFieldType(eagle, field)}, "");
}
}
errorsWarnings.warnings.push(issue);
field.errorsArray.push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}


Expand All @@ -864,25 +873,29 @@ export class Field {
//check that the field has an id
if (field.getId() === "" || field.getId() === null){
const issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has field (" + field.getDisplayText() + ") with no id", function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixFieldId(eagle, field)}, "Generate id for field");
errorsWarnings.errors.push(issue);
field.errorsArray.push({issue:issue,validity:Errors.Validity.Error})
// errorsWarnings.errors.push(issue);
}

// check that the field has a default value
if (field.getDefaultValue() === "" && !field.isType(Daliuge.DataType.String) && !field.isType(Daliuge.DataType.Password) && !field.isType(Daliuge.DataType.Object) && !field.isType(Daliuge.DataType.Unknown)) {
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has a component parameter (" + field.getDisplayText() + ") whose default value is not specified", function(){Utils.showField(eagle, node.getId(),field)}, function(){Utils.fixFieldDefaultValue(eagle, field)}, "Generate default value for parameter");
errorsWarnings.warnings.push(issue);
field.errorsArray.push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}

//chack that the field has a known type
if (!Utils.validateType(field.getType())) {
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has a component parameter (" + field.getDisplayText() + ") whose type (" + field.getType() + ") is unknown", function(){Utils.showField(eagle, node.getId(),field)}, function(){Utils.fixFieldType(eagle, field)}, "Prepend existing type (" + field.getType() + ") with 'Object.'");
errorsWarnings.warnings.push(issue);
field.errorsArray.push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}

// check that the fields "key" is the same as the key of the node it belongs to
if (field.getNodeKey() !== node.getKey()) {
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has a field (" + field.getDisplayText() + ") whose key (" + field.getNodeKey() + ") doesn't match the node (" + node.getKey() + ")", function(){Utils.showField(eagle, node.getId(),field)}, function(){Utils.fixFieldKey(eagle, node, field)}, "Set field node key correctly");
errorsWarnings.errors.push(issue);
field.errorsArray.push({issue:issue,validity:Errors.Validity.Error})
// errorsWarnings.errors.push(issue);
}

//check that the field has a unique display text on the node
Expand All @@ -895,10 +908,12 @@ export class Field {
if (field.getDisplayText() === field1.getDisplayText() && field.getParameterType() === field1.getParameterType()){
if (field.getId() === field1.getId()){
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has multiple attributes with the same display text and id (" + field.getDisplayText() + ").", function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixNodeMergeFieldsByIndex(eagle, node, fieldIndex, j)}, "Merge fields");
errorsWarnings.warnings.push(issue);
field.errorsArray.push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
} else {
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has multiple attributes with the same display text (" + field.getDisplayText() + ").", function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixNodeMergeFields(eagle, node, field, field1)}, "Merge fields");
errorsWarnings.warnings.push(issue);
field.errorsArray.push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}
}
}
Expand Down Expand Up @@ -929,13 +944,14 @@ export class Field {

const message = "Node " + node.getKey() + " (" + node.getName() + ") with category " + node.getCategory() + " contains field (" + field.getDisplayText() + ") with unsuitable type (" + field.getParameterType() + ").";
const issue: Errors.Issue = Errors.ShowFix(message, function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixFieldParameterType(eagle, node, field, suitableType)}, "Switch to suitable type, or remove if no suitable type");
errorsWarnings.warnings.push(issue);
field.errorsArray.push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}
}

field.errorsWarnings(errorsWarnings)
// field.errorsWarnings(errorsWarnings)

return errorsWarnings
// return errorsWarnings
}

public static sortFunc(a: Field, b: Field) : number {
Expand Down
Loading

0 comments on commit 3d29bdc

Please sign in to comment.