Skip to content

Commit a02735e

Browse files
authored
Merge pull request microsoft#32785 from amcasey/FileNotFoundError
Include fewer paths in exception
2 parents 9133e7a + 6c19c13 commit a02735e

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/server/session.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ namespace ts.server {
689689
this.logErrorWorker(err, cmd);
690690
}
691691

692-
private logErrorWorker(err: Error, cmd: string, fileRequest?: protocol.FileRequestArgs): void {
692+
private logErrorWorker(err: Error & PossibleProgramFileInfo, cmd: string, fileRequest?: protocol.FileRequestArgs): void {
693693
let msg = "Exception on executing command " + cmd;
694694
if (err.message) {
695695
msg += ":\n" + indent(err.message);
@@ -711,7 +711,9 @@ namespace ts.server {
711711
catch { } // tslint:disable-line no-empty
712712
}
713713

714-
if (err.message && err.message.indexOf(`Could not find sourceFile:`) !== -1) {
714+
715+
if (err.ProgramFiles) {
716+
msg += `\n\nProgram files: {JSON.stringify(error.ProgramFiles}}\n`;
715717
msg += `\n\nProjects::\n`;
716718
let counter = 0;
717719
const addProjectInfo = (project: Project) => {

src/services/services.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,13 @@ namespace ts {
11581158
function getValidSourceFile(fileName: string): SourceFile {
11591159
const sourceFile = program.getSourceFile(fileName);
11601160
if (!sourceFile) {
1161-
throw new Error(`Could not find sourceFile: '${fileName}' in ${program && JSON.stringify(program.getSourceFiles().map(f => f.fileName))}.`);
1161+
const error: Error & PossibleProgramFileInfo = new Error(`Could not find sourceFile: '${fileName}'.`);
1162+
1163+
// We've been having trouble debugging this, so attach sidecar data for the tsserver log.
1164+
// See https://github.com/microsoft/TypeScript/issues/30180.
1165+
error.ProgramFiles = program.getSourceFiles().map(f => f.fileName);
1166+
1167+
throw error;
11621168
}
11631169
return sourceFile;
11641170
}

src/services/utilities.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,11 @@ namespace ts {
967967
readonly called: Identifier;
968968
readonly nTypeArguments: number;
969969
}
970+
971+
export interface PossibleProgramFileInfo {
972+
ProgramFiles?: string[];
973+
}
974+
970975
// Get info for an expression like `f <` that may be the start of type arguments.
971976
export function getPossibleTypeArgumentsInfo(tokenIn: Node, sourceFile: SourceFile): PossibleTypeArgumentInfo | undefined {
972977
let token: Node | undefined = tokenIn;

src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ namespace ts.projectSystem {
139139
assert.isTrue(false, `should not find file '${imported.path}'`);
140140
}
141141
catch (e) {
142-
assert.isTrue(e.message.indexOf(`Could not find sourceFile: '${imported.path}' in ["${root.path}"].`) === 0, `Actual: ${e.message}`);
142+
assert.isTrue(e.message.indexOf(`Could not find sourceFile: '${imported.path}'.`) === 0, `Actual: ${e.message}`);
143143
}
144144
const f2Lookups = getLocationsForModuleLookup("f2");
145145
callsTrackingHost.verifyCalledOnEachEntryNTimes(CalledMapsWithSingleArg.fileExists, f2Lookups, 1);

0 commit comments

Comments
 (0)