Skip to content

Commit

Permalink
Make engine version optional (#7975)
Browse files Browse the repository at this point in the history
Fixes this issue:
- #7917

This is caused by the dashboard expecting `engineVersion` to be present, whereas it is actually optional.

# Important Notes
This may have been fixed on the Project Manager side, so the bug may not be reproducible. To properly test that this fix works, an older `project-manager` (e.g `2023.2.1-nightly.2023.9.30`) should be used.
  • Loading branch information
somebody1234 authored Oct 9, 2023
1 parent 8125200 commit 6a127c5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,17 @@ export interface ProjectRaw extends ListedProjectRaw {

/** A user/organization's project containing and/or currently executing code. */
export interface Project extends ListedProject {
/** This must not be null as it is required to determine the base URL for backend assets. */
ideVersion: VersionNumber
ideVersion: VersionNumber | null
engineVersion: VersionNumber | null
openedBy?: EmailAddress
}

/** A user/organization's project containing and/or currently executing code. */
export interface BackendProject extends Project {
/** This must not be null as it is required to determine the base URL for backend assets. */
ideVersion: VersionNumber
}

/** Information required to open a project. */
export interface ProjectStartupInfo {
project: Project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export default function Editor(props: EditorProps) {
let assetsRoot: string
switch (backendType) {
case backendModule.BackendType.remote: {
if (project.ideVersion == null) {
toastAndLog('Could not get the IDE version of the project')
// This is too deeply nested to easily return from
// eslint-disable-next-line no-restricted-syntax
return
}
assetsRoot = `${IDE_CDN_BASE_URL}/${project.ideVersion.value}/`
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export class LocalBackend extends backend.Backend {
override rootDirectoryId(): backend.DirectoryId {
return backend.DirectoryId('')
}

/** Return a list of assets in a directory.
*
* @throws An error if the JSON-RPC call fails. */
Expand Down Expand Up @@ -146,26 +145,24 @@ export class LocalBackend extends backend.Backend {
if (cachedProject == null) {
const result = await this.projectManager.listProjects({})
const project = result.projects.find(listedProject => listedProject.id === projectId)
const engineVersion = project?.engineVersion
if (project == null) {
throw new Error(
`Could not get details of project ${
title != null ? `'${title}'` : `with ID '${projectId}'`
}.`
)
} else if (engineVersion == null) {
throw new Error(`The project '${project.name}' does not have an engine version.`)
} else {
const version =
project.engineVersion == null
? null
: {
lifecycle: backend.detectVersionLifecycle(project.engineVersion),
value: project.engineVersion,
}
return {
name: project.name,
engineVersion: {
lifecycle: backend.detectVersionLifecycle(engineVersion),
value: engineVersion,
},
ideVersion: {
lifecycle: backend.detectVersionLifecycle(engineVersion),
value: engineVersion,
},
engineVersion: version,
ideVersion: version,
jsonAddress: null,
binaryAddress: null,
organizationId: '',
Expand Down Expand Up @@ -255,22 +252,20 @@ export class LocalBackend extends backend.Backend {
}
const result = await this.projectManager.listProjects({})
const project = result.projects.find(listedProject => listedProject.id === projectId)
const engineVersion = project?.engineVersion
const version =
project?.engineVersion == null
? null
: {
lifecycle: backend.detectVersionLifecycle(project.engineVersion),
value: project.engineVersion,
}
if (project == null) {
throw new Error(`The project ID '${projectId}' is invalid.`)
} else if (engineVersion == null) {
throw new Error(`The project '${project.name}' does not have an engine version.`)
} else {
return {
ami: null,
engineVersion: {
lifecycle: backend.VersionLifecycle.stable,
value: engineVersion,
},
ideVersion: {
lifecycle: backend.VersionLifecycle.stable,
value: engineVersion,
},
engineVersion: version,
ideVersion: version,
name: project.name,
organizationId: '',
projectId,
Expand Down Expand Up @@ -302,7 +297,7 @@ export class LocalBackend extends backend.Backend {
}
}

/** Do nothing. This function should never need to be called. */
/** Return a list of engine versions. */
override async listVersions(params: backend.ListVersionsRequestParams) {
const engineVersions = await this.projectManager.listAvailableEngineVersions()
const engineVersionToVersion = (
Expand All @@ -318,7 +313,7 @@ export class LocalBackend extends backend.Backend {
// eslint-disable-next-line @typescript-eslint/naming-convention
version_type: params.versionType,
})
return engineVersions.map(engineVersionToVersion)
return engineVersions.versions.map(engineVersionToVersion)
}

// === Endpoints that intentionally do not work on the Local Backend ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export interface EngineVersion {
markedAsBroken: boolean
}

/** The return value of the "list available engine versions" endpoint. */
export interface VersionList {
versions: EngineVersion[]
}

// ================================
// === Parameters for endpoints ===
// ================================
Expand Down Expand Up @@ -272,9 +277,14 @@ export class ProjectManager extends EventTarget {
return this.sendRequest('project/delete', params)
}

/** List installed engine versions. */
public listInstalledEngineVersions(): Promise<VersionList> {
return this.sendRequest<VersionList>('engine/list-installed', {})
}

/** List available engine versions. */
public listAvailableEngineVersions(): Promise<[EngineVersion, ...EngineVersion[]]> {
return this.sendRequest<[EngineVersion, ...EngineVersion[]]>('engine/list-available', {})
public listAvailableEngineVersions(): Promise<VersionList> {
return this.sendRequest<VersionList>('engine/list-available', {})
}

/** Remove all handlers for a specified request ID. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ export class RemoteBackend extends backendModule.Backend {
}
}

/** Return list of backend or IDE versions.
/** Return a list of backend or IDE versions.
*
* @throws An error if a non-successful status code (not 200-299) was received. */
override async listVersions(
Expand Down

0 comments on commit 6a127c5

Please sign in to comment.