Skip to content

Commit

Permalink
fix diagnostics not being reported in the cli after config parse erro…
Browse files Browse the repository at this point in the history
…rs are reported
  • Loading branch information
DetachHead committed Dec 15, 2024
1 parent a472a2d commit 304f26d
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 44 deletions.
3 changes: 0 additions & 3 deletions packages/pyright-internal/src/analyzer/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface AnalysisResults {
checkingOnlyOpenFiles: boolean;
requiringAnalysisCount: RequiringAnalysisCount;
fatalErrorOccurred: boolean;
configParseErrorOccurred: boolean;
elapsedTime: number;
error?: Error | undefined;
reason: 'analysis' | 'tracking';
Expand Down Expand Up @@ -75,7 +74,6 @@ export function analyzeProgram(
requiringAnalysisCount: requiringAnalysisCount,
checkingOnlyOpenFiles: program.isCheckingOnlyOpenFiles(),
fatalErrorOccurred: false,
configParseErrorOccurred: false,
elapsedTime,
reason: 'analysis',
});
Expand All @@ -94,7 +92,6 @@ export function analyzeProgram(
requiringAnalysisCount: { files: 0, cells: 0 },
checkingOnlyOpenFiles: true,
fatalErrorOccurred: true,
configParseErrorOccurred: false,
elapsedTime: 0,
error: debug.getSerializableError(e),
reason: 'analysis',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ export class BackgroundAnalysisProgram {
requiringAnalysisCount: this._program.getFilesToAnalyzeCount(),
checkingOnlyOpenFiles: this._program.isCheckingOnlyOpenFiles(),
fatalErrorOccurred: false,
configParseErrorOccurred: false,
elapsedTime: 0,
reason: 'tracking',
});
Expand Down
17 changes: 0 additions & 17 deletions packages/pyright-internal/src/analyzer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,6 @@ export class AnalyzerService {
fileContents = this.fs.readFileSync(fileUri, 'utf8');
} catch {
this._console.error(`Config file "${fileUri.toUserVisibleString()}" could not be read.`);
this._reportConfigParseError();
return undefined;
}

Expand All @@ -1201,7 +1200,6 @@ export class AnalyzerService {
this._console.error(
`Config file "${fileUri.toUserVisibleString()}" could not be parsed. Verify that format is correct.`
);
this._reportConfigParseError();
return undefined;
}
}
Expand Down Expand Up @@ -1920,19 +1918,4 @@ export class AnalyzerService {
this.runAnalysis(this._backgroundAnalysisCancellationSource.token);
}, timeUntilNextAnalysisInMs);
}

private _reportConfigParseError() {
if (this._onCompletionCallback) {
this._onCompletionCallback({
diagnostics: [],
filesInProgram: 0,
requiringAnalysisCount: { files: 0, cells: 0 },
checkingOnlyOpenFiles: true,
fatalErrorOccurred: false,
configParseErrorOccurred: true,
elapsedTime: 0,
reason: 'analysis',
});
}
}
}
2 changes: 0 additions & 2 deletions packages/pyright-internal/src/backgroundAnalysisBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase
requiringAnalysisCount: requiringAnalysisCount,
checkingOnlyOpenFiles: this.program.isCheckingOnlyOpenFiles(),
fatalErrorOccurred: false,
configParseErrorOccurred: false,
elapsedTime: 0,
reason: 'analysis',
});
Expand Down Expand Up @@ -763,7 +762,6 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase
requiringAnalysisCount: requiringAnalysisCount,
checkingOnlyOpenFiles: this.program.isCheckingOnlyOpenFiles(),
fatalErrorOccurred: false,
configParseErrorOccurred: false,
elapsedTime,
reason: 'tracking',
});
Expand Down
22 changes: 3 additions & 19 deletions packages/pyright-internal/src/pyright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,23 +543,11 @@ const outputResults = (
* checks for errors parsing config files and / or the baseline file and exits with a non-zero exit code
* if there were any
*/
const checkForErrors = (
exitStatus: Deferred<ExitStatus>,
configParseErrorOccurred: boolean,
console: ConsoleInterface
): boolean => {
const checkForErrors = (exitStatus: Deferred<ExitStatus>, console: ConsoleInterface) => {
if (console instanceof StandardConsole && console.errorWasLogged) {
console.errorWasLogged = false;
exitStatus.resolve(ExitStatus.ConfigFileParseError);
return true;
}
// in basedpyright configParseErrorOccurred is redundant since we track the errors in the StandardConsole
// but we keep it just in case an upstream change relies on it without also calling console.error
if (configParseErrorOccurred) {
exitStatus.resolve(ExitStatus.ConfigFileParseError);
return true;
}
return false;
};

async function runSingleThreaded(
Expand All @@ -579,9 +567,7 @@ async function runSingleThreaded(
return;
}

if (checkForErrors(exitStatus, results.configParseErrorOccurred, output)) {
return;
}
checkForErrors(exitStatus, output);

const errorCount =
args.createstub || args.verifytypes
Expand Down Expand Up @@ -774,9 +760,7 @@ async function runMultiThreaded(
return;
}

if (checkForErrors(exitStatus, results.configParseErrorOccurred, console)) {
return;
}
checkForErrors(exitStatus, console);

for (const fileDiag of results.diagnostics) {
fileDiagnostics.push(FileDiagnostics.fromJsonObj(fileDiag));
Expand Down
3 changes: 1 addition & 2 deletions packages/pyright-internal/src/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ test('both pyright and basedpyright in pyproject.toml', () => {
'src/tests/samples/project_with_both_config_sections_in_pyproject_toml'
);
assert.strictEqual(configOptions.defaultPythonVersion!, undefined);
assert(analysisResult?.configParseErrorOccurred);
assert(!analysisResult.fatalErrorOccurred);
assert(!analysisResult?.fatalErrorOccurred);
});

test('invalid option value in pyproject.toml', () => {
Expand Down

0 comments on commit 304f26d

Please sign in to comment.