mirror of
https://github.com/microsoft/pyright.git
synced 2024-08-17 03:40:44 +03:00
Added code to command-line version to report a non-zero exit code if the config file couldn't be read or parsed.
This commit is contained in:
parent
bc22f60eed
commit
358abe62e4
@ -30,4 +30,5 @@ Pyright can be run as either a VS Code extension or as a node-based command-line
|
||||
| 0 | No errors reported |
|
||||
| 1 | One or more errors reported |
|
||||
| 2 | Fatal error occurred with no errors or warnings reported |
|
||||
| 3 | Config file could not be read or parsed |
|
||||
|
||||
|
@ -39,6 +39,7 @@ export interface AnalysisResults {
|
||||
filesInProgram: number;
|
||||
filesRequiringAnalysis: number;
|
||||
fatalErrorOccurred: boolean;
|
||||
configParseErrorOccurred: boolean;
|
||||
elapsedTime: number;
|
||||
}
|
||||
|
||||
@ -510,6 +511,7 @@ export class AnalyzerService {
|
||||
configContents = fs.readFileSync(configPath, { encoding: 'utf8' });
|
||||
} catch {
|
||||
this._console.log(`Config file "${ configPath }" could not be read.`);
|
||||
this._reportConfigParseError();
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -532,7 +534,8 @@ export class AnalyzerService {
|
||||
// resulting in parse errors. We'll give it a little more time and
|
||||
// try again.
|
||||
if (parseAttemptCount++ >= 5) {
|
||||
this._console.log(`Config file "${ configPath }" could not be parsed.`);
|
||||
this._console.log(`Config file "${ configPath }" could not be parsed. Verify that JSON is correct.`);
|
||||
this._reportConfigParseError();
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@ -876,6 +879,7 @@ export class AnalyzerService {
|
||||
filesInProgram: this._program.getFileCount(),
|
||||
filesRequiringAnalysis: filesLeftToAnalyze,
|
||||
fatalErrorOccurred: false,
|
||||
configParseErrorOccurred: false,
|
||||
elapsedTime: duration.getDurationInSeconds()
|
||||
};
|
||||
|
||||
@ -896,6 +900,7 @@ export class AnalyzerService {
|
||||
filesInProgram: 0,
|
||||
filesRequiringAnalysis: 0,
|
||||
fatalErrorOccurred: true,
|
||||
configParseErrorOccurred: false,
|
||||
elapsedTime: 0
|
||||
});
|
||||
}
|
||||
@ -912,9 +917,23 @@ export class AnalyzerService {
|
||||
filesInProgram: this._program.getFileCount(),
|
||||
filesRequiringAnalysis: this._program.getFilesToAnalyzeCount(),
|
||||
fatalErrorOccurred: false,
|
||||
configParseErrorOccurred: false,
|
||||
elapsedTime: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _reportConfigParseError() {
|
||||
if (this._onCompletionCallback) {
|
||||
this._onCompletionCallback({
|
||||
diagnostics: [],
|
||||
filesInProgram: 0,
|
||||
filesRequiringAnalysis: 0,
|
||||
fatalErrorOccurred: false,
|
||||
configParseErrorOccurred: true,
|
||||
elapsedTime: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,8 @@ const toolName = 'pyright';
|
||||
enum ExitStatus {
|
||||
NoErrors = 0,
|
||||
ErrorsReported = 1,
|
||||
FatalError = 2
|
||||
FatalError = 2,
|
||||
ConfigFileParseError = 3
|
||||
}
|
||||
|
||||
interface DiagnosticResult {
|
||||
@ -119,6 +120,10 @@ function processArgs() {
|
||||
process.exit(ExitStatus.FatalError);
|
||||
}
|
||||
|
||||
if (results.configParseErrorOccurred) {
|
||||
process.exit(ExitStatus.ConfigFileParseError);
|
||||
}
|
||||
|
||||
let errorCount = 0;
|
||||
if (results.diagnostics.length > 0 && !args.createstub) {
|
||||
const report = reportDiagnostics(results.diagnostics);
|
||||
|
Loading…
Reference in New Issue
Block a user