diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 2f5ff604df3..57ad0260cb6 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -68,7 +68,7 @@ var sys: System = (function () { return fileStream.ReadText(); } catch (e) { - throw e.number === -2147024809 ? new Error(ts.Diagnostics.Unsupported_file_encoding.key) : e; + throw e; } finally { fileStream.Close(); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index c8cccd2da1c..52dac9695de 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -142,14 +142,19 @@ module ts { // otherwise use toLowerCase as a canonical form. return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); } - + + // returned by CScript sys environment + var unsupportedFileEncodingErrorCode = -2147024809; + function getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile { try { var text = sys.readFile(filename, options.charset); } catch (e) { if (onError) { - onError(e.message); + onError(e.number === unsupportedFileEncodingErrorCode ? + getDiagnosticText(Diagnostics.Unsupported_file_encoding) : + e.message); } text = ""; }