fix js string undefined (#2045)
* fix js string undefined Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes for tests Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -34,7 +34,7 @@ const part = startSketchOn('XY')
|
|||||||
{
|
{
|
||||||
// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
|
// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
|
||||||
arcDegrees: number,
|
arcDegrees: number,
|
||||||
// The center about which to make th pattern. This is a 2D vector.
|
// The center about which to make the pattern. This is a 2D vector.
|
||||||
center: [number, number],
|
center: [number, number],
|
||||||
// The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once.
|
// The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once.
|
||||||
repetitions: number,
|
repetitions: number,
|
||||||
|
@ -42,7 +42,7 @@ const part = startSketchOn('XY')
|
|||||||
arcDegrees: number,
|
arcDegrees: number,
|
||||||
// The axis around which to make the pattern. This is a 3D vector.
|
// The axis around which to make the pattern. This is a 3D vector.
|
||||||
axis: [number, number, number],
|
axis: [number, number, number],
|
||||||
// The center about which to make th pattern. This is a 3D vector.
|
// The center about which to make the pattern. This is a 3D vector.
|
||||||
center: [number, number, number],
|
center: [number, number, number],
|
||||||
// The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once.
|
// The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once.
|
||||||
repetitions: number,
|
repetitions: number,
|
||||||
|
@ -42165,7 +42165,7 @@
|
|||||||
"format": "double"
|
"format": "double"
|
||||||
},
|
},
|
||||||
"center": {
|
"center": {
|
||||||
"description": "The center about which to make th pattern. This is a 2D vector.",
|
"description": "The center about which to make the pattern. This is a 2D vector.",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
@ -44168,7 +44168,7 @@
|
|||||||
"minItems": 3
|
"minItems": 3
|
||||||
},
|
},
|
||||||
"center": {
|
"center": {
|
||||||
"description": "The center about which to make th pattern. This is a 3D vector.",
|
"description": "The center about which to make the pattern. This is a 3D vector.",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
|
@ -25,7 +25,8 @@ interface CommandInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebSocketResponse = Models['OkWebSocketResponseData_type']
|
type WebSocketResponse = Models['WebSocketResponse_type']
|
||||||
|
type OkWebSocketResponseData = Models['OkWebSocketResponseData_type']
|
||||||
|
|
||||||
interface ResultCommand extends CommandInfo {
|
interface ResultCommand extends CommandInfo {
|
||||||
type: 'result'
|
type: 'result'
|
||||||
@ -37,10 +38,19 @@ interface FailedCommand extends CommandInfo {
|
|||||||
type: 'failed'
|
type: 'failed'
|
||||||
errors: Models['FailureWebSocketResponse_type']['errors']
|
errors: Models['FailureWebSocketResponse_type']['errors']
|
||||||
}
|
}
|
||||||
|
interface ResolveCommand {
|
||||||
|
id: string
|
||||||
|
commandType: CommandTypes
|
||||||
|
range: SourceRange
|
||||||
|
// We ALWAYS need the raw response because we pass it back to the rust side.
|
||||||
|
raw: WebSocketResponse
|
||||||
|
data?: Models['OkModelingCmdResponse_type']
|
||||||
|
errors?: Models['FailureWebSocketResponse_type']['errors']
|
||||||
|
}
|
||||||
interface PendingCommand extends CommandInfo {
|
interface PendingCommand extends CommandInfo {
|
||||||
type: 'pending'
|
type: 'pending'
|
||||||
promise: Promise<any>
|
promise: Promise<any>
|
||||||
resolve: (val: any) => void
|
resolve: (val: ResolveCommand) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ArtifactMap {
|
export interface ArtifactMap {
|
||||||
@ -827,7 +837,7 @@ export type CommandLog =
|
|||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'receive-reliable'
|
type: 'receive-reliable'
|
||||||
data: WebSocketResponse
|
data: OkWebSocketResponseData
|
||||||
id: string
|
id: string
|
||||||
cmd_type?: string
|
cmd_type?: string
|
||||||
}
|
}
|
||||||
@ -1020,7 +1030,11 @@ export class EngineCommandManager {
|
|||||||
message.resp.type === 'modeling' &&
|
message.resp.type === 'modeling' &&
|
||||||
message.request_id
|
message.request_id
|
||||||
) {
|
) {
|
||||||
this.handleModelingCommand(message.resp, message.request_id)
|
this.handleModelingCommand(
|
||||||
|
message.resp,
|
||||||
|
message.request_id,
|
||||||
|
message
|
||||||
|
)
|
||||||
} else if (
|
} else if (
|
||||||
!message.success &&
|
!message.success &&
|
||||||
message.request_id &&
|
message.request_id &&
|
||||||
@ -1069,7 +1083,11 @@ export class EngineCommandManager {
|
|||||||
}
|
}
|
||||||
this.engineConnection?.send(resizeCmd)
|
this.engineConnection?.send(resizeCmd)
|
||||||
}
|
}
|
||||||
handleModelingCommand(message: WebSocketResponse, id: string) {
|
handleModelingCommand(
|
||||||
|
message: OkWebSocketResponseData,
|
||||||
|
id: string,
|
||||||
|
raw: WebSocketResponse
|
||||||
|
) {
|
||||||
if (message.type !== 'modeling') {
|
if (message.type !== 'modeling') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1081,7 +1099,7 @@ export class EngineCommandManager {
|
|||||||
command?.additionalData?.type === 'batch-ids'
|
command?.additionalData?.type === 'batch-ids'
|
||||||
) {
|
) {
|
||||||
command.additionalData.ids.forEach((id) => {
|
command.additionalData.ids.forEach((id) => {
|
||||||
this.handleModelingCommand(message, id)
|
this.handleModelingCommand(message, id, raw)
|
||||||
})
|
})
|
||||||
// batch artifact is just a container, we don't need to keep it
|
// batch artifact is just a container, we don't need to keep it
|
||||||
// once we process all the commands inside it
|
// once we process all the commands inside it
|
||||||
@ -1092,7 +1110,7 @@ export class EngineCommandManager {
|
|||||||
commandType: command.commandType,
|
commandType: command.commandType,
|
||||||
range: command.range,
|
range: command.range,
|
||||||
data: modelingResponse,
|
data: modelingResponse,
|
||||||
raw: message,
|
raw,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1116,7 +1134,7 @@ export class EngineCommandManager {
|
|||||||
commandType: command.commandType,
|
commandType: command.commandType,
|
||||||
parentId: command.parentId ? command.parentId : undefined,
|
parentId: command.parentId ? command.parentId : undefined,
|
||||||
data: modelingResponse,
|
data: modelingResponse,
|
||||||
raw: message,
|
raw,
|
||||||
} as const
|
} as const
|
||||||
this.artifactMap[id] = artifact
|
this.artifactMap[id] = artifact
|
||||||
if (
|
if (
|
||||||
@ -1161,7 +1179,7 @@ export class EngineCommandManager {
|
|||||||
commandType: command.commandType,
|
commandType: command.commandType,
|
||||||
range: command.range,
|
range: command.range,
|
||||||
data: modelingResponse,
|
data: modelingResponse,
|
||||||
raw: message,
|
raw,
|
||||||
})
|
})
|
||||||
} else if (sceneCommand && sceneCommand.type === 'pending') {
|
} else if (sceneCommand && sceneCommand.type === 'pending') {
|
||||||
const resolve = sceneCommand.resolve
|
const resolve = sceneCommand.resolve
|
||||||
@ -1172,7 +1190,7 @@ export class EngineCommandManager {
|
|||||||
commandType: sceneCommand.commandType,
|
commandType: sceneCommand.commandType,
|
||||||
parentId: sceneCommand.parentId ? sceneCommand.parentId : undefined,
|
parentId: sceneCommand.parentId ? sceneCommand.parentId : undefined,
|
||||||
data: modelingResponse,
|
data: modelingResponse,
|
||||||
raw: message,
|
raw,
|
||||||
} as const
|
} as const
|
||||||
this.sceneCommandArtifacts[id] = artifact
|
this.sceneCommandArtifacts[id] = artifact
|
||||||
resolve({
|
resolve({
|
||||||
@ -1180,6 +1198,7 @@ export class EngineCommandManager {
|
|||||||
commandType: sceneCommand.commandType,
|
commandType: sceneCommand.commandType,
|
||||||
range: sceneCommand.range,
|
range: sceneCommand.range,
|
||||||
data: modelingResponse,
|
data: modelingResponse,
|
||||||
|
raw,
|
||||||
})
|
})
|
||||||
} else if (command) {
|
} else if (command) {
|
||||||
this.artifactMap[id] = {
|
this.artifactMap[id] = {
|
||||||
@ -1188,7 +1207,7 @@ export class EngineCommandManager {
|
|||||||
range: command?.range,
|
range: command?.range,
|
||||||
pathToNode: command?.pathToNode,
|
pathToNode: command?.pathToNode,
|
||||||
data: modelingResponse,
|
data: modelingResponse,
|
||||||
raw: message,
|
raw,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.sceneCommandArtifacts[id] = {
|
this.sceneCommandArtifacts[id] = {
|
||||||
@ -1197,15 +1216,14 @@ export class EngineCommandManager {
|
|||||||
range: sceneCommand?.range,
|
range: sceneCommand?.range,
|
||||||
pathToNode: sceneCommand?.pathToNode,
|
pathToNode: sceneCommand?.pathToNode,
|
||||||
data: modelingResponse,
|
data: modelingResponse,
|
||||||
raw: message,
|
raw,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleFailedModelingCommand({
|
handleFailedModelingCommand(raw: WebSocketResponse) {
|
||||||
request_id,
|
const id = raw.request_id
|
||||||
errors,
|
const failed = raw as Models['FailureWebSocketResponse_type']
|
||||||
}: Models['FailureWebSocketResponse_type']) {
|
const errors = failed.errors
|
||||||
const id = request_id
|
|
||||||
if (!id) return
|
if (!id) return
|
||||||
const command = this.artifactMap[id]
|
const command = this.artifactMap[id]
|
||||||
if (command && command.type === 'pending') {
|
if (command && command.type === 'pending') {
|
||||||
@ -1223,6 +1241,7 @@ export class EngineCommandManager {
|
|||||||
commandType: command.commandType,
|
commandType: command.commandType,
|
||||||
range: command.range,
|
range: command.range,
|
||||||
errors,
|
errors,
|
||||||
|
raw,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.artifactMap[id] = {
|
this.artifactMap[id] = {
|
||||||
@ -1573,7 +1592,14 @@ export class EngineCommandManager {
|
|||||||
command: commandStr,
|
command: commandStr,
|
||||||
ast: this.getAst(),
|
ast: this.getAst(),
|
||||||
idToRangeMap,
|
idToRangeMap,
|
||||||
}).then(({ raw }) => JSON.stringify(raw))
|
}).then(({ raw }: { raw: WebSocketResponse | undefined | null }) => {
|
||||||
|
if (raw === undefined || raw === null) {
|
||||||
|
throw new Error(
|
||||||
|
'returning modeling cmd response to the rust side is undefined or null'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return JSON.stringify(raw)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
commandResult(id: string): Promise<any> {
|
commandResult(id: string): Promise<any> {
|
||||||
const command = this.artifactMap[id]
|
const command = this.artifactMap[id]
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
import { Models } from '@kittycad/lib'
|
import { Models } from '@kittycad/lib'
|
||||||
import { Themes } from './theme'
|
import { Themes } from './theme'
|
||||||
|
|
||||||
type WebSocketResponse = Models['OkWebSocketResponseData_type']
|
type WebSocketResponse = Models['WebSocketResponse_type']
|
||||||
|
|
||||||
class MockEngineCommandManager {
|
class MockEngineCommandManager {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
||||||
@ -27,10 +27,13 @@ class MockEngineCommandManager {
|
|||||||
command: EngineCommand
|
command: EngineCommand
|
||||||
}): Promise<any> {
|
}): Promise<any> {
|
||||||
const response: WebSocketResponse = {
|
const response: WebSocketResponse = {
|
||||||
|
success: true,
|
||||||
|
resp: {
|
||||||
type: 'modeling',
|
type: 'modeling',
|
||||||
data: {
|
data: {
|
||||||
modeling_response: { type: 'empty' },
|
modeling_response: { type: 'empty' },
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return Promise.resolve(JSON.stringify(response))
|
return Promise.resolve(JSON.stringify(response))
|
||||||
}
|
}
|
||||||
|
@ -99,13 +99,25 @@ impl crate::engine::EngineManager for EngineConnection {
|
|||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let modeling_result: kittycad::types::OkWebSocketResponseData = serde_json::from_str(&s).map_err(|e| {
|
let ws_result: kittycad::types::WebSocketResponse = serde_json::from_str(&s).map_err(|e| {
|
||||||
KclError::Engine(KclErrorDetails {
|
KclError::Engine(KclErrorDetails {
|
||||||
message: format!("Failed to deserialize response from engine: {:?}", e),
|
message: format!("Failed to deserialize response from engine: {:?}", e),
|
||||||
source_ranges: vec![source_range],
|
source_ranges: vec![source_range],
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(modeling_result)
|
if let Some(data) = &ws_result.resp {
|
||||||
|
Ok(data.clone())
|
||||||
|
} else if let Some(errors) = &ws_result.errors {
|
||||||
|
Err(KclError::Engine(KclErrorDetails {
|
||||||
|
message: format!("Modeling command failed: {:?}", errors),
|
||||||
|
source_ranges: vec![source_range],
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
Err(KclError::Engine(KclErrorDetails {
|
||||||
|
message: format!("Modeling command failed: {:?}", ws_result),
|
||||||
|
source_ranges: vec![source_range],
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ pub struct CircularPattern2dData {
|
|||||||
/// This excludes the original entity. For example, if `repetitions` is 1,
|
/// This excludes the original entity. For example, if `repetitions` is 1,
|
||||||
/// the original entity will be copied once.
|
/// the original entity will be copied once.
|
||||||
pub repetitions: u32,
|
pub repetitions: u32,
|
||||||
/// The center about which to make th pattern. This is a 2D vector.
|
/// The center about which to make the pattern. This is a 2D vector.
|
||||||
pub center: [f64; 2],
|
pub center: [f64; 2],
|
||||||
/// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
|
/// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
|
||||||
pub arc_degrees: f64,
|
pub arc_degrees: f64,
|
||||||
@ -254,7 +254,7 @@ pub struct CircularPattern3dData {
|
|||||||
pub repetitions: u32,
|
pub repetitions: u32,
|
||||||
/// The axis around which to make the pattern. This is a 3D vector.
|
/// The axis around which to make the pattern. This is a 3D vector.
|
||||||
pub axis: [f64; 3],
|
pub axis: [f64; 3],
|
||||||
/// The center about which to make th pattern. This is a 3D vector.
|
/// The center about which to make the pattern. This is a 3D vector.
|
||||||
pub center: [f64; 3],
|
pub center: [f64; 3],
|
||||||
/// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
|
/// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
|
||||||
pub arc_degrees: f64,
|
pub arc_degrees: f64,
|
||||||
|
Reference in New Issue
Block a user