Skip to content

Commit

Permalink
Updatre code owner file and refactor errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Sep 6, 2024
1 parent 161b66c commit e0f2437
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# See: https://help.github.com/articles/about-codeowners/

# These owners will be the default owners for everything in the repo.
* @hasithaa @prakanth97 @SasinduDilshara
* @hasithaa @SasinduDilshara
4 changes: 2 additions & 2 deletions ballerina/tests/parse_string_union_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function testParseStringUnionTypes2() {

S22|error a22 = parseString(s2);
test:assertTrue(a22 is Error);
test:assertEquals((<error> a22).message(), "source value cannot convert into 'ballerina/data.xmldata:1:S22'");
test:assertEquals((<error> a22).message(), "source value cannot be converted into 'ballerina/data.xmldata:1:S22'");

// https://github.com/ballerina-platform/ballerina-library/issues/6925
// S23|error a23 = parseString(s2);
Expand Down Expand Up @@ -248,7 +248,7 @@ function testParseStringUnionTypes7() {

S73|error a73 = parseString(s7);
test:assertTrue(a73 is Error);
test:assertEquals((<error>a73).message(), "field 'B' cannot convert into the type '(data.xmldata:record {| string @content; |}|string[])'");
test:assertEquals((<error>a73).message(), "field 'B' cannot be converted into the type '(data.xmldata:record {| string @content; |}|string[])'");

// //bug https://github.com/ballerina-platform/ballerina-library/issues/6907
// S74|error a74 = parseString(s7);
Expand Down
4 changes: 2 additions & 2 deletions ballerina/tests/parse_type_union_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function testTraverseUnionTypes2() {

A22|error a22 = parseAsType(x2);
test:assertTrue(a22 is Error);
test:assertEquals((<error> a22).message(), "source value cannot convert into 'ballerina/data.xmldata:1:A22'");
test:assertEquals((<error> a22).message(), "source value cannot be converted into 'ballerina/data.xmldata:1:A22'");

// https://github.com/ballerina-platform/ballerina-library/issues/6925
// A23|error a23 = parseAsType(x2);
Expand Down Expand Up @@ -247,7 +247,7 @@ function testTraverseUnionTypes7() {

A73|error a73 = parseAsType(x7);
test:assertTrue(a73 is Error);
test:assertEquals((<error>a73).message(), "field 'B' cannot convert into the type '(data.xmldata:record {| string @content; |}|string[])'");
test:assertEquals((<error>a73).message(), "field 'B' cannot be converted into the type '(data.xmldata:record {| string @content; |}|string[])'");

// //bug https://github.com/ballerina-platform/ballerina-library/issues/6907
// A74|error a74 = parseAsType(x7);
Expand Down
16 changes: 8 additions & 8 deletions ballerina/tests/union_error_tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -117,33 +117,33 @@ type G112 record {
function testErrorUnion() {
E1|error e1 = parseAsType(xe1);
test:assertTrue(e1 is error);
test:assertEquals((<error>e1).message(), "field '#content' cannot convert into the type '(boolean|int|decimal|data.xmldata:record {| anydata...; |})?'");
test:assertEquals((<error>e1).message(), "field '#content' cannot be converted into the type '(boolean|int|decimal|data.xmldata:record {| anydata...; |})?'");

E2|error e2 = parseAsType(xe2);
test:assertTrue(e2 is error);
test:assertEquals((<error>e2).message(), "field '#content' cannot convert into the type '(boolean|int|decimal|data.xmldata:record {| anydata...; |})?'");
test:assertEquals((<error>e2).message(), "field '#content' cannot be converted into the type '(boolean|int|decimal|data.xmldata:record {| anydata...; |})?'");

E22|error e22 = parseAsType(xe2);
test:assertTrue(e22 is error);
test:assertEquals((<error>e22).message(), "field 'B' cannot convert into the type '(data.xmldata:record {| (boolean|int|decimal|record {| anydata...; |})? #content; anydata...; |}|data.xmldata:record {| record {| int #content; anydata...; |} #content; anydata...; |})'");
test:assertEquals((<error>e22).message(), "field 'B' cannot be converted into the type '(data.xmldata:record {| (boolean|int|decimal|record {| anydata...; |})? #content; anydata...; |}|data.xmldata:record {| record {| int #content; anydata...; |} #content; anydata...; |})'");

E3|error e3 = parseAsType(xe3);
test:assertTrue(e3 is error);
test:assertEquals((<error>e3).message(), "field 'B' cannot convert into the type '(data.xmldata:record {| int #content; anydata...; |}|data.xmldata:record {| boolean #content; anydata...; |})[]'");
test:assertEquals((<error>e3).message(), "field 'B' cannot be converted into the type '(data.xmldata:record {| int #content; anydata...; |}|data.xmldata:record {| boolean #content; anydata...; |})[]'");

E32|error e32 = parseAsType(xe3);
test:assertTrue(e32 is error);
test:assertEquals((<error>e32).message(), "field 'B' cannot convert into the type '(data.xmldata:record {| int #content; anydata...; |}[]|data.xmldata:record {| boolean #content; anydata...; |}[])'");
test:assertEquals((<error>e32).message(), "field 'B' cannot be converted into the type '(data.xmldata:record {| int #content; anydata...; |}[]|data.xmldata:record {| boolean #content; anydata...; |}[])'");

E4|error e4 = parseAsType(xe4);
test:assertTrue(e4 is error);
test:assertEquals((<error>e4).message(), "field 'C' cannot convert into the type 'data.xmldata:E4P12[]'");
test:assertEquals((<error>e4).message(), "field 'C' cannot be converted into the type 'data.xmldata:E4P12[]'");

E42|error e42 = parseAsType(xe4);
test:assertTrue(e42 is error);
test:assertEquals((<error>e42).message(), "field 'C' cannot convert into the type 'ballerina/data.xmldata:1:E4P22'");
test:assertEquals((<error>e42).message(), "field 'C' cannot be converted into the type 'ballerina/data.xmldata:1:E4P22'");

E5|error e5 = parseAsType(xe5);
test:assertTrue(e5 is error);
test:assertEquals((<error>e5).message(), "field 'B' cannot convert into the type '(data.xmldata:F111|data.xmldata:F112)[]'");
test:assertEquals((<error>e5).message(), "field 'B' cannot be converted into the type '(data.xmldata:F111|data.xmldata:F112)[]'");
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ private static Object convertStringToUnionExpType(BString value, Type expType) {
try {
return convertStringToExpType(value, memberType);
} catch (Exception ex) {
int a = 1;
// ignore
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,34 @@ public Object traverseXml(BXml xml, XmlAnalyzerData analyzerData, Type type) {
Type referredType = TypeUtils.getReferredType(type);
switch (referredType.getTag()) {
case TypeTags.RECORD_TYPE_TAG -> {
return traverseXmlWithRecordAsExpectedType(xml, analyzerData, referredType);
return traverseXmlWithRecordAsExpectedType(xml, analyzerData, (RecordType) referredType);
}
case TypeTags.MAP_TAG -> {
return traverseXmlWithMapAsExpectedType(xml, referredType, analyzerData);
return traverseXmlWithMapAsExpectedType(xml, (MapType) referredType, analyzerData);
}
case TypeTags.UNION_TAG -> {
return traverseXmlToUnion(xml, analyzerData, referredType);
return traverseXmlToUnion(xml, analyzerData, (UnionType) referredType);
}
default -> throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, Constants.RECORD_OR_MAP, type);
}
}

private Object traverseXmlWithRecordAsExpectedType(BXml xml,
XmlAnalyzerData analyzerData, Type referredType) {
RecordType recordType = (RecordType) referredType;
XmlAnalyzerData analyzerData, RecordType recordType) {
currentNode = ValueCreator.createRecordValue(recordType.getPackage(), recordType.getName());
BXml nextXml = validateRootElement(xml, recordType, analyzerData);
Object resultRecordValue = traverseXml(nextXml, recordType, analyzerData);
DataUtils.validateRequiredFields(analyzerData, (BMap<BString, Object>) currentNode);
return resultRecordValue;
}

private Object traverseXmlWithMapAsExpectedType(BXml xml, Type referredType, XmlAnalyzerData analyzerData) {
MapType mapType = (MapType) referredType;
private Object traverseXmlWithMapAsExpectedType(BXml xml, MapType mapType, XmlAnalyzerData analyzerData) {
RecordType anonRecType = TypeCreator.createRecordType(Constants.ANON_TYPE, mapType.getPackage(), 0,
new HashMap<>(), mapType.getConstrainedType(), false, 0);
return traverseXml(xml, analyzerData, anonRecType);
}

private Object traverseXmlToUnion(BXml xml, XmlAnalyzerData options, Type type) {
UnionType unionType = (UnionType) type;
private Object traverseXmlToUnion(BXml xml, XmlAnalyzerData options, UnionType unionType) {
XmlAnalyzerData clonedAnalyzerData = XmlAnalyzerData.copy(options);
for (Type memberType: unionType.getMemberTypes()) {
memberType = TypeUtils.getReferredType(memberType);
Expand All @@ -133,12 +130,11 @@ private Object traverseXmlToUnion(BXml xml, XmlAnalyzerData options, Type type)
}
return traverseXml(xml, options, memberType);
} catch (Exception ex) {
int a = 1;
options.resetFrom(clonedAnalyzerData);
// ignore
}
}
throw DiagnosticLog.error(DiagnosticErrorCode.CANNOT_CONVERT_SOURCE_INTO_EXP_TYPE, type);
throw DiagnosticLog.error(DiagnosticErrorCode.CANNOT_CONVERT_SOURCE_INTO_EXP_TYPE, unionType);
}

private Object traverseXml(BXml xml, Type type, XmlAnalyzerData analyzerData) {
Expand Down Expand Up @@ -190,7 +186,6 @@ private void convertText(String text, XmlAnalyzerData analyzerData) {
fieldType = memberType;
break;
} catch (Exception ex) {
int a = 1;
analyzerData.resetFrom(clonedAnalyzerData);
// ignore
}
Expand Down Expand Up @@ -318,7 +313,6 @@ private void convertFieldTypeToUnion(BXmlItem xmlItem, Field currentField, Strin
} catch (Exception ex) {
analyzerData.resetFrom(clonedAnalyzerData);
mapValue.put(StringUtils.fromString(fieldName), null);
int a = 1;
// ignore
}
}
Expand Down Expand Up @@ -381,7 +375,6 @@ private void convertToUnionMemberType(BXmlItem xmlItem, String fieldName, ArrayT
return;
} catch (Exception ex) {
analyzerData.resetFrom(clonedAnalyzerData);
int a = 1;
// ignore
}
}
Expand Down Expand Up @@ -537,7 +530,6 @@ private void checkRestTypeAndConvertForUnionTypes(BXmlItem xmlItem, String elemN
if (restType.getTag() != TypeTags.ARRAY_TAG) {
mapValue.put(StringUtils.fromString(elemName), null);
}
int a = 1;
// ignore
}
}
Expand Down
4 changes: 2 additions & 2 deletions native/src/main/resources/error.properties
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ error.undefined.field=\
undefined field ''{0}'' in record ''{1}''

error.cannot.convert.source.into.expected.type=\
source value cannot convert into ''{0}''
source value cannot be converted into ''{0}''

error.field.cannot.convert.into.type=\
field ''{0}'' cannot convert into the type ''{1}''
field ''{0}'' cannot be converted into the type ''{1}''

0 comments on commit e0f2437

Please sign in to comment.