Skip to content

Commit 408f77d

Browse files
author
Eric Prud'hommeaux
committed
~ feedback from shapetrees-js@2ef2476
1 parent 58ab9c5 commit 408f77d

File tree

28 files changed

+198
-184
lines changed

28 files changed

+198
-184
lines changed

asTypescript/packages/client-http/src/HttpResourceAccessor.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,11 @@ export class HttpResourceAccessor implements ResourceAccessor {
279279
if (location.isPresent()) {
280280
try {
281281
url = new URL(location.get());
282-
} catch (ex) {
283-
if (ex instanceof MalformedURLException) {
282+
} catch (e) {
283+
if (e instanceof MalformedURLException) {
284284
throw new ShapeTreeException(500, "Retrieving <" + url + "> yielded a Location header \"" + location.get() + "\" which doesn't parse as a URL: " + e.getMessage());
285-
}
285+
}}
286+
286287
}
287288
// Determine whether the resource exists based on the response. Even if the resource
288289
// doesn't exist, additional context and processing is done to provide the appropriate
@@ -354,7 +355,8 @@ export class HttpResourceAccessor implements ResourceAccessor {
354355
} catch (ex) {
355356
if (ex instanceof Exception) {
356357
throw new ShapeTreeException(500, ex.getMessage());
357-
}
358+
}}
359+
358360
}
359361

360362
/**
@@ -453,10 +455,11 @@ export class HttpResourceAccessor implements ResourceAccessor {
453455
let managerUrlString: string = optManagerString.get();
454456
try {
455457
return Optional.of(new URL(url, managerUrlString));
456-
} catch (ex) {
457-
if (ex instanceof MalformedURLException) {
458+
} catch (e) {
459+
if (e instanceof MalformedURLException) {
458460
throw new ShapeTreeException(500, "Malformed relative URL <" + managerUrlString + "> (resolved from <" + url + ">)");
459-
}
461+
}}
462+
460463
}
461464

462465
/**
@@ -482,10 +485,11 @@ export class HttpResourceAccessor implements ResourceAccessor {
482485
}
483486
try {
484487
managedResourceUrl = new URL(managerUrl, managedUrlString);
485-
} catch (ex) {
486-
if (ex instanceof MalformedURLException) {
488+
} catch (e) {
489+
if (e instanceof MalformedURLException) {
487490
throw new ShapeTreeException(500, "Can't calculate managed resource for shape tree manager <" + managerUrl + ">");
488-
}
491+
}}
492+
489493
return managedResourceUrl;
490494
}
491495

asTypescript/packages/core/src/ManageableResource.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ export class ManageableResource extends InstanceResource {
4444
const rel: string = this.isContainer() ? ".." : ".";
4545
try {
4646
return new URL(this.getUrl(), rel);
47-
} catch (ex) {
48-
if (ex instanceof MalformedURLException) {
47+
} catch (e) {
48+
if (e instanceof MalformedURLException) {
4949
throw new ShapeTreeException(500, "Malformed focus node when resolving <" + rel + "> against <" + this.getUrl() + ">");
50-
}
50+
}}
51+
5152
}
5253

5354
public getManagerResourceUrl(): URL | null {

asTypescript/packages/core/src/ShapeTree.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export class ShapeTree {
115115
} catch (ex) {
116116
if (ex instanceof Exception) {
117117
throw new ShapeTreeException(500, "Error parsing ShEx schema - " + ex.getMessage());
118-
}
118+
}}
119+
119120
}
120121
// Tell ShExJava we want to use Jena as our graph library
121122
let jenaRDF: JenaRDF = new org.apache.commons.rdf.jena.JenaRDF();
@@ -151,7 +152,8 @@ export class ShapeTree {
151152
} catch (ex) {
152153
if (ex instanceof MalformedURLException) {
153154
throw new ShapeTreeException(500, "Error reporting validation success on malformed URL <" + focusUriString + ">: " + ex.getMessage());
154-
}
155+
}}
156+
155157
return new ValidationResult(valid, this, this, matchingFocusNode);
156158
}
157159
}

asTypescript/packages/core/src/ShapeTreeAssignment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export class ShapeTreeAssignment {
5656
} catch (ex) {
5757
if (ex instanceof NullPointerException || ex instanceof IllegalStateException) {
5858
throw new ShapeTreeException(500, "Failed to initialize shape tree assignment: " + ex.getMessage());
59-
}
59+
}}
60+
6061
}
6162

6263
public static getFromGraph(url: URL, managerGraph: Graph): ShapeTreeAssignment /* throws MalformedURLException, ShapeTreeException */ {

asTypescript/packages/core/src/ShapeTreeFactory.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export class ShapeTreeFactory {
9191
} catch (ex) {
9292
if (ex instanceof MalformedURLException || ex instanceof ShapeTreeException) {
9393
throw new ShapeTreeException(500, "List <" + shapeTreeUrl + "> contains malformed URL: " + ex.getMessage());
94-
}
94+
}}
95+
9596
}
9697

9798
/**
@@ -117,7 +118,8 @@ export class ShapeTreeFactory {
117118
} catch (ex) {
118119
if (ex instanceof MalformedURLException) {
119120
throw new ShapeTreeException(500, "ShapeTree <" + shapeTreeUrl + "> references malformed URL <" + referencedShapeTreeUrlString + ">: " + ex.getMessage());
120-
}
121+
}}
122+
121123
let viaShapePath: string = getStringValue(resourceModel, referenceResource, ShapeTreeVocabulary.VIA_SHAPE_PATH);
122124
let viaPredicate: URL = getUrlValue(resourceModel, referenceResource, ShapeTreeVocabulary.VIA_PREDICATE, shapeTreeUrl);
123125
referencedShapeTree = new ShapeTreeReference(referencedShapeTreeUrl, viaShapePath, viaPredicate);
@@ -147,7 +149,8 @@ export class ShapeTreeFactory {
147149
} catch (ex) {
148150
if (ex instanceof MalformedURLException) {
149151
throw new IllegalStateException("Malformed ShapeTree <" + shapeTreeUrl + ">: Jena URIResource <" + object + "> didn't parse as URL - " + ex.getMessage());
150-
}
152+
}}
153+
151154
} else {
152155
throw new ShapeTreeException(500, "Malformed ShapeTree <" + shapeTreeUrl + ">: expected " + object + " to be a URL");
153156
}

asTypescript/packages/core/src/ShapeTreeManager.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export class ShapeTreeManager {
106106
} catch (ex) {
107107
if (ex instanceof MalformedURLException) {
108108
throw new IllegalStateException("Minted illegal URL <" + assignmentString + "> - " + ex.getMessage());
109-
}
109+
}}
110+
110111
return assignmentUrl;
111112
}
112113

@@ -164,10 +165,11 @@ export class ShapeTreeManager {
164165
let assignment: ShapeTreeAssignment = null;
165166
try {
166167
assignment = ShapeTreeAssignment.getFromGraph(new URL(assignmentNode.getObject().getURI()), managerGraph);
167-
} catch (ex) {
168-
if (ex instanceof MalformedURLException) {
168+
} catch (e) {
169+
if (e instanceof MalformedURLException) {
169170
throw new ShapeTreeException(500, "Object of { " + s + " " + stAssignment + " " + assignmentNode.getObject() + " } must be a URL.");
170-
}
171+
}}
172+
171173
manager.assignments.add(assignment);
172174
}
173175
return manager;

asTypescript/packages/core/src/ShapeTreeManagerDelta.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export class ShapeTreeManagerDelta {
8282
} catch (ex) {
8383
if (ex instanceof URISyntaxException) {
8484
throw new ShapeTreeException(500, "Unable to convert assignment URLs for comparison: " + ex.getMessage());
85-
}
85+
}}
86+
8687
if (assignmentUri === targetAssignmentUri) {
8788
return targetAssignment;
8889
}

asTypescript/packages/core/src/contentloaders/HttpExternalDocumentLoader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class HttpExternalDocumentLoader implements ExternalDocumentLoader {
3333
throw new ShapeTreeException(500, "Error retrieving <" + resourceUrl + ">: " + ex.getMessage());
3434
} else if (ex instanceof URISyntaxException) {
3535
throw new ShapeTreeException(500, "Malformed URL <" + resourceUrl + ">: " + ex.getMessage());
36-
}
36+
}}
37+
3738
}
3839
}

asTypescript/packages/core/src/helpers/GraphHelper.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ export class GraphHelper {
7777
let reader: StringReader = new StringReader(rawContent);
7878
RDFDataMgr.read(model.getGraph(), reader, baseURI.toString(), GraphHelper.getLangForContentType(contentType));
7979
return model;
80-
} catch (ex) {
81-
if (ex instanceof RiotException) {
80+
} catch (rex) {
81+
if (rex instanceof RiotException) {
8282
throw new ShapeTreeException(422, "Error processing input - " + rex.getMessage());
83-
}
83+
}}
84+
8485
}
8586

8687
/**
@@ -164,7 +165,8 @@ export class GraphHelper {
164165
} catch (ex) {
165166
if (ex instanceof URISyntaxException) {
166167
throw new IllegalStateException("can't convert URL <" + url + "> to IRI: " + ex);
167-
}
168+
}}
169+
168170
}
169171

170172
/**
@@ -183,7 +185,8 @@ export class GraphHelper {
183185
} catch (ex) {
184186
if (ex instanceof MalformedURLException || ex instanceof URISyntaxException) {
185187
throw new IllegalStateException("Unable to remove fragment from URL: " + ex.getMessage());
186-
}
188+
}}
189+
187190
}
188191

189192
public static knownUrl(urlString: string): URL {
@@ -192,6 +195,7 @@ export class GraphHelper {
192195
} catch (ex) {
193196
if (ex instanceof MalformedURLException) {
194197
throw new IllegalStateException("Expected known URL <" + urlString + "> to parse as valid URL - " + ex.toString());
195-
}
198+
}}
199+
196200
}
197201
}

asTypescript/packages/core/src/helpers/RequestHelper.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ export class RequestHelper {
9797
try {
9898
const focusNodeUrl: URL = new URL(baseUrl, focusNodeUrlString);
9999
focusNodeUrls.add(focusNodeUrl);
100-
} catch (ex) {
101-
if (ex instanceof MalformedURLException) {
100+
} catch (e) {
101+
if (e instanceof MalformedURLException) {
102102
throw new ShapeTreeException(500, "Malformed focus node when resolving <" + focusNodeUrlString + "> against <" + baseUrl + ">");
103-
}
103+
}}
104+
104105
}
105106
}
106107
return focusNodeUrls;
@@ -120,10 +121,11 @@ export class RequestHelper {
120121
try {
121122
const targetShapeTreeUrl: URL = new URL(targetShapeTreeUrlString);
122123
targetShapeTreeUrls.add(targetShapeTreeUrl);
123-
} catch (ex) {
124-
if (ex instanceof MalformedURLException) {
124+
} catch (e) {
125+
if (e instanceof MalformedURLException) {
125126
throw new ShapeTreeException(500, "Malformed focus node when resolving <" + targetShapeTreeUrlString + "> against <" + baseUrl + ">");
126-
}
127+
}}
128+
127129
}
128130
}
129131
return targetShapeTreeUrls;
@@ -158,7 +160,8 @@ export class RequestHelper {
158160
} catch (ex) {
159161
if (ex instanceof MalformedURLException) {
160162
throw new ShapeTreeException(500, "normalized to malformed URL <" + urlString + "> - " + ex.getMessage());
161-
}
163+
}}
164+
162165
}
163166

164167
/**

0 commit comments

Comments
 (0)