Skip to content

Commit

Permalink
Handle 404 fetch better.
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed May 31, 2018
1 parent 8edb339 commit c150c32
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ export function resolveModule(
util.assert(moduleSpecifier != null && moduleSpecifier.length > 0);
// We ask golang to sourceCodeFetch. It will load the sourceCode and if
// there is any outputCode cached, it will return that as well.
const { filename, sourceCode, outputCode } = os.codeFetch(
moduleSpecifier,
containingFile
);
let fetchResponse;
try {
fetchResponse = os.codeFetch(moduleSpecifier, containingFile);
} catch(e) {
// TODO Only catch "no such file or directory" errors. Need error codes.
return null;
}
const { filename, sourceCode, outputCode } = fetchResponse;
if (sourceCode.length === 0) {
return null;
}
Expand All @@ -165,9 +169,13 @@ export function resolveModule(
function resolveModuleName(
moduleSpecifier: string,
containingFile: string
): string {
): string | undefined {
const mod = resolveModule(moduleSpecifier, containingFile);
return mod.fileName;
if (mod) {
return mod.fileName;
} else {
return undefined;
}
}

function execute(fileName: string, outputCode: string): void {
Expand Down Expand Up @@ -308,6 +316,9 @@ class TypeScriptHost implements ts.LanguageServiceHost {
resolvedFileName = resolveModuleName("typescript.d.ts", "/$asset$/");
} else {
resolvedFileName = resolveModuleName(name, containingFile);
if (resolvedFileName == null) {
return undefined;
}
}
const isExternalLibraryImport = false;
return { resolvedFileName, isExternalLibraryImport };
Expand Down

0 comments on commit c150c32

Please sign in to comment.