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

Check if modalityd is reachable on startup #35

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
91 changes: 91 additions & 0 deletions vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@
"@viz-js/viz": "^3.0.1",
"@vscode/codicons": "^0.0.32",
"@vscode/webview-ui-toolkit": "^1.4.0",
"axios": "^1.6.8",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we already have an http client library in the deps tree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAICT we're only using openapi-fetch for our http client stuff, which also uses axios behind the scenes.

"cytoscape": "^3.28.1",
"cytoscape-context-menus": "^4.1.0",
"cytoscape-cose-bilkent": "^4.1.0",
Expand Down
10 changes: 9 additions & 1 deletion vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ let lspClient: LanguageClient;
export async function activate(context: vscode.ExtensionContext) {
log = vscode.window.createOutputChannel("Auxon");

const apiUrl = await config.modalityUrl();
const modalitydIsAlive = await api.isModalitydReachable(apiUrl.toString());
if (!modalitydIsAlive) {
const msg =
`The Auxon Modality backend server cannot be reached at '${apiUrl}'. ` +
`If modalityd is not running locally, set the 'auxon.modalityUrl' configuration`;
throw new Error(msg);
}

// If this is a fresh install, prompt for new first user creation
await user.handleNewUserCreation();

lspClient = await lsp.activateLspClient(context);

const apiUrl = await config.modalityUrl();
const allowInsecure = await config.allowInsecureHttps();
let token = await config.userAuthToken();

Expand Down
14 changes: 14 additions & 0 deletions vscode/src/modalityApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as gen from "./generated/src/modality-api";
import createClient from "openapi-fetch";
import axios from "axios";

// See https://github.com/ajaishankar/openapi-typescript-fetch#server-side-usage
import fetch, { Headers, Request, Response } from "node-fetch";
Expand Down Expand Up @@ -75,6 +76,19 @@ export type Experiment = gen.components["schemas"]["Experiment"];

type InternalClient = ReturnType<typeof createClient<gen.paths>>;

export async function isModalitydReachable(baseUrl: string): Promise<boolean> {
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.slice(0, -1);
}
const url = baseUrl + "/v1/alive";
try {
const _response = await axios.get(url);
} catch (_exception) {
return false;
}
return true;
}

export class Client {
client: InternalClient;

Expand Down
Loading