Fix type of sketchGroup function (#3316)

This commit is contained in:
Jonathan Tran
2024-08-07 15:15:22 -04:00
committed by GitHub
parent 308a0fb06e
commit 9dc7ff9797

View File

@ -381,6 +381,7 @@ export class SceneEntities {
programMemory, programMemory,
}) })
if (err(sketchGroup)) return Promise.reject(sketchGroup) if (err(sketchGroup)) return Promise.reject(sketchGroup)
if (!sketchGroup) return Promise.reject('sketchGroup not found')
if (!Array.isArray(sketchGroup?.value)) if (!Array.isArray(sketchGroup?.value))
return { return {
@ -916,6 +917,10 @@ export class SceneEntities {
programMemory: kclManager.programMemory, programMemory: kclManager.programMemory,
}) })
if (trap(sketchGroup)) return if (trap(sketchGroup)) return
if (!sketchGroup) {
trap(new Error('sketchGroup not found'))
return
}
const pipeIndex = pathToNode[pathToNodeIndex + 1][0] as number const pipeIndex = pathToNode[pathToNodeIndex + 1][0] as number
if (addingNewSegmentStatus === 'nothing') { if (addingNewSegmentStatus === 'nothing') {
@ -1765,7 +1770,7 @@ export function sketchGroupFromPathToNode({
pathToNode: PathToNode pathToNode: PathToNode
ast: Program ast: Program
programMemory: ProgramMemory programMemory: ProgramMemory
}): SketchGroup | Error { }): SketchGroup | null | Error {
const _varDec = getNodeFromPath<VariableDeclarator>( const _varDec = getNodeFromPath<VariableDeclarator>(
kclManager.ast, kclManager.ast,
pathToNode, pathToNode,
@ -1777,7 +1782,10 @@ export function sketchGroupFromPathToNode({
if (result?.type === 'ExtrudeGroup') { if (result?.type === 'ExtrudeGroup') {
return result.sketchGroup return result.sketchGroup
} }
return result as SketchGroup if (result?.type === 'SketchGroup') {
return result
}
return null
} }
function colorSegment(object: any, color: number) { function colorSegment(object: any, color: number) {
@ -1830,6 +1838,7 @@ export async function getSketchOrientationDetails(
programMemory: kclManager.programMemory, programMemory: kclManager.programMemory,
}) })
if (err(sketchGroup)) return Promise.reject(sketchGroup) if (err(sketchGroup)) return Promise.reject(sketchGroup)
if (!sketchGroup) return Promise.reject('sketchGroup not found')
if (sketchGroup.on.type === 'plane') { if (sketchGroup.on.type === 'plane') {
const zAxis = sketchGroup?.on.zAxis const zAxis = sketchGroup?.on.zAxis