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

Cleanup KernelStartException from unneeded areas #2886

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public async Task<IEnumerable<KernelSpec>> GetKernelSpecsAsync()

byte[] bytes = await response.Content.ReadAsByteArrayAsync();
var list = JsonSerializer.Deserialize<KernelSpecs>(bytes);
_availableKernels = list?.kernelspecs?.Select(t => {
_availableKernels = list?.kernelspecs?.Select(t =>
{
var spec = t.Value.spec;
spec.Name ??= t.Key;
return spec;
Expand All @@ -118,30 +119,23 @@ public async Task<IJupyterKernelConnection> CreateKernelConnectionAsync(string k
type = "notebook"
};

try
{
HttpResponseMessage response = await _apiClient.SendRequestAsync(
relativeApiPath: "api/sessions",
content: new StringContent(JsonSerializer.Serialize(body), Encoding.UTF8, "application/json"),
method: HttpMethod.Post
);
HttpResponseMessage response = await _apiClient.SendRequestAsync(
relativeApiPath: "api/sessions",
content: new StringContent(JsonSerializer.Serialize(body), Encoding.UTF8, "application/json"),
method: HttpMethod.Post
);

if (!response.IsSuccessStatusCode)
{
throw new KernelStartException(kernelSpecName, response.ReasonPhrase);
}

byte[] bytes = await response.Content.ReadAsByteArrayAsync();
var session = JsonSerializer.Deserialize<KernelSessionInfo>(bytes);
_activeSessions.Add(session.id);
var kernelApiClient = _apiClient.CreateClient($"api/kernels/{session.kernel.id}");

return new JupyterKernelHttpConnection(kernelApiClient, _authProvider);
}
catch (Exception e)
if (!response.IsSuccessStatusCode)
{
throw new KernelStartException(kernelSpecName, e.Message);
throw new KernelStartException(kernelSpecName, response.ReasonPhrase);
}

byte[] bytes = await response.Content.ReadAsByteArrayAsync();
var session = JsonSerializer.Deserialize<KernelSessionInfo>(bytes);
_activeSessions.Add(session.id);
var kernelApiClient = _apiClient.CreateClient($"api/kernels/{session.kernel.id}");

return new JupyterKernelHttpConnection(kernelApiClient, _authProvider);
}

private async Task<bool> ShutdownJupyterSessionsAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<IJupyterKernelConnection> CreateKernelConnectionAsync(string k

if (spec is null)
{
throw new KernelStartException(kernelSpecName, "kernel not found");
throw new ArgumentException($"KernelSpec {kernelSpecName} not found");
}

ConnectionInformation connectionInfo = null;
Expand Down