Skip to content

Commit 397c37d

Browse files
authored
Merge pull request #330 from redhat-developer/revert-324-323-catchThrownErrorInOtherExtensions
Revert "Catch errors that can be thrown by registered schema providers #323"
2 parents 2dfb3d5 + 70717c9 commit 397c37d

File tree

2 files changed

+14
-42
lines changed

2 files changed

+14
-42
lines changed

src/schema-extension-api.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,24 @@ class SchemaExtensionAPI implements ExtensionAPI {
9292
public requestCustomSchema(resource: string): string[] {
9393
const matches = [];
9494
for (let customKey of Object.keys(this._customSchemaContributors)) {
95-
try {
96-
const contributor = this._customSchemaContributors[customKey];
97-
let uri: string;
98-
if (contributor.label && workspace.textDocuments) {
99-
const labelRegexp = new RegExp(contributor.label, 'g');
100-
for (const doc of workspace.textDocuments) {
101-
if (doc.uri.toString() === resource) {
102-
if (labelRegexp.test(doc.getText())) {
103-
uri = contributor.requestSchema(resource);
104-
return [uri];
105-
}
95+
const contributor = this._customSchemaContributors[customKey];
96+
let uri: string;
97+
if (contributor.label && workspace.textDocuments) {
98+
const labelRegexp = new RegExp(contributor.label, 'g');
99+
for (const doc of workspace.textDocuments) {
100+
if (doc.uri.toString() === resource) {
101+
if (labelRegexp.test(doc.getText())) {
102+
uri = contributor.requestSchema(resource);
103+
return [uri];
106104
}
107105
}
108106
}
107+
}
109108

110-
uri = contributor.requestSchema(resource);
109+
uri = contributor.requestSchema(resource);
111110

112-
if (uri) {
113-
matches.push(uri);
114-
}
115-
} catch (error) {
116-
console.log(`Error thrown while requesting schema ` + error);
111+
if (uri) {
112+
matches.push(uri);
117113
}
118114
}
119115
return matches;

test/schemaProvider.test.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import { getDocUri, activate, testCompletion, testHover, testDiagnostics, sleep } from './helper';
8+
import { Uri } from 'vscode';
89

910
describe('Tests for schema provider feature', () => {
1011
const docUri = getDocUri('completion/completion.yaml');
@@ -133,23 +134,6 @@ describe('Tests for schema provider feature', () => {
133134
}
134135
]
135136
});
136-
});
137-
138-
it('Multiple contributors with one throwing an error', async () => {
139-
const client = await activate(docUri);
140-
client._customSchemaContributors = {};
141-
client.registerContributor(SCHEMA2, onRequestSchema2URI, onRequestSchema2Content);
142-
client.registerContributor("schemathrowingerror", onRequestSchemaURIThrowError, onRequestSchemaContentThrowError);
143-
144-
await testCompletion(docUri, new vscode.Position(0, 0), {
145-
items: [
146-
{
147-
label: "apple",
148-
kind: 9,
149-
documentation: "An apple"
150-
}
151-
]
152-
});
153137
});
154138
});
155139

@@ -177,14 +161,6 @@ function onRequestSchema1URI(resource: string): string | undefined {
177161
return undefined;
178162
}
179163

180-
function onRequestSchemaURIThrowError(resource: string): string | undefined {
181-
throw new Error('test what happens when an error is thrown and not caught');
182-
}
183-
184-
function onRequestSchemaContentThrowError(schemaUri: string): string | undefined {
185-
throw new Error('test what happens when an error is thrown and not caught');
186-
}
187-
188164
function onRequestSchema1Content(schemaUri: string): string | undefined {
189165
return schemaJSON;
190166
}

0 commit comments

Comments
 (0)