Skip to content

Commit

Permalink
[json] `Unable to load schema, EISDIR: illegal operation on a directo…
Browse files Browse the repository at this point in the history
…ry (#236319)
  • Loading branch information
aeschli authored Dec 17, 2024
1 parent f5e5ee4 commit f283262
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions extensions/json-language-features/server/src/node/jsonServerMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { formatError } from '../utils/runner';
import { RequestService, RuntimeEnvironment, startServer } from '../jsonServer';

import { xhr, XHRResponse, configure as configureHttpRequests, getErrorStatusDescription } from 'request-light';
import { URI as Uri } from 'vscode-uri';
import * as fs from 'fs';
import { promises as fs } from 'fs';
import * as l10n from '@vscode/l10n';

// Create a connection for the server.
const connection: Connection = createConnection();
Expand All @@ -36,16 +36,17 @@ function getHTTPRequestService(): RequestService {

function getFileRequestService(): RequestService {
return {
getContent(location: string, encoding?: BufferEncoding) {
return new Promise((c, e) => {
const uri = Uri.parse(location);
fs.readFile(uri.fsPath, encoding, (err, buf) => {
if (err) {
return e(err);
}
c(buf.toString());
});
});
async getContent(location: string, encoding?: BufferEncoding) {
try {
return (await fs.readFile(location, encoding)).toString();
} catch (e) {
if (e.code === 'ENOENT') {
throw new Error(l10n.t('Schema not found: {0}', location));
} else if (e.code === 'EISDIR') {
throw new Error(l10n.t('{0} is a directory, not a file', location));
}
throw e;
}
}
};
}
Expand Down

0 comments on commit f283262

Please sign in to comment.