Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove process.exit commands #467

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions libs/interpreter-lib/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
collectStartingBlocks,
createJayveeServices,
getBlocksInTopologicalSorting,
initializeWorkspace,
} from '@jvalue/jayvee-language-server';
import * as chalk from 'chalk';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -82,16 +83,25 @@ export async function interpretModel(
', ',
)}.`,
);
process.exit(ExitCode.FAILURE);
return ExitCode.FAILURE;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should distinguish between different kinds of FAILURES, like CONFIGURATION_FAILURE, RUNTIME_FAILURE, RUNTIME_ERROR, and so on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good, yeah. Note though, this is the exit code of the process so we can not freely define new ones (afaik). We definitely should have some form of more elaborate error output outside of the exit code though, like writing a logfile.

}

useStdExtension();
registerDefaultConstraintExecutors();

const services = createJayveeServices(NodeFileSystem).Jayvee;
await initializeWorkspace(services);
setupJayveeServices(services, options.env);

const model = await extractAstNodeFn(services, loggerFactory);
let model: JayveeModel;
try {
model = await extractAstNodeFn(services, loggerFactory);
} catch (e) {
loggerFactory
.createLogger()
.logErr('Could not extract the AST node of the given model.');
return ExitCode.FAILURE;
}

const debugTargets = getDebugTargets(options.debugTarget);

Expand Down
6 changes: 3 additions & 3 deletions libs/interpreter-lib/src/parsing-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export async function extractDocumentFromFile(
}: ${extensions.map((extension) => `"${extension}"`).join(',')}`;

logger.logErr(errorMessage);
process.exit(ExitCode.FAILURE);
return Promise.reject(ExitCode.FAILURE);
}

if (!fs.existsSync(fileName)) {
logger.logErr(`File ${fileName} does not exist.`);
process.exit(ExitCode.FAILURE);
return Promise.reject(ExitCode.FAILURE);
}

const document =
Expand Down Expand Up @@ -79,7 +79,7 @@ export async function validateDocument(
for (const errDiagnostic of errDiagnostics) {
logger.logLanguageServerDiagnostic(errDiagnostic, document);
}
process.exit(ExitCode.FAILURE);
return Promise.reject(ExitCode.FAILURE);
}

const nonErrDiagnostics = diagnostics.filter(
Expand Down
Loading