internal: Add lints for promises (#3733)
* Add lints for floating and misued promises * Add logging async errors in main * Add async error catch in test-utils * Change any to unknown * Trap promise errors and ignore more await warnings * Add more ignores and toSync helper * Fix more lint warnings * Add more ignores and fixes * Add more reject reporting * Add accepting arbitrary parameters to toSync() * Fix more lints * Revert unintentional change to non-arrow function * Revert unintentional change to use arrow function * Fix new warnings in main with auto updater * Fix formatting * Change lints to error This is what the recommended type checked rules do. * Fix to properly report promise rejections * Fix formatting * Fix formatting * Remove unused import * Remove unused convenience function * Move type helpers * Fix to not return promise when caller doesn't expect it * Add ignores to lsp code
This commit is contained in:
@ -14,6 +14,8 @@ import { isDesktop } from 'lib/isDesktop'
|
||||
import { Themes } from './theme'
|
||||
import { commandBarMachine } from 'machines/commandBarMachine'
|
||||
import { getNextFileName } from './desktopFS'
|
||||
import { reportRejection } from './trap'
|
||||
import { toSync } from './utils'
|
||||
|
||||
export async function submitTextToCadPrompt(
|
||||
prompt: string,
|
||||
@ -128,37 +130,42 @@ export async function submitAndAwaitTextToKcl({
|
||||
// Check the status of the text-to-cad API job
|
||||
// until it is completed
|
||||
const textToCadComplete = new Promise<Models['TextToCad_type']>(
|
||||
async (resolve, reject) => {
|
||||
const value = await textToCadQueued
|
||||
if (value instanceof Error) {
|
||||
reject(value)
|
||||
}
|
||||
|
||||
const MAX_CHECK_TIMEOUT = 3 * 60_000
|
||||
const CHECK_INTERVAL = 3000
|
||||
|
||||
let timeElapsed = 0
|
||||
const interval = setInterval(async () => {
|
||||
timeElapsed += CHECK_INTERVAL
|
||||
if (timeElapsed >= MAX_CHECK_TIMEOUT) {
|
||||
clearInterval(interval)
|
||||
reject(new Error('Text-to-CAD API timed out'))
|
||||
(resolve, reject) => {
|
||||
;(async () => {
|
||||
const value = await textToCadQueued
|
||||
if (value instanceof Error) {
|
||||
reject(value)
|
||||
}
|
||||
|
||||
const check = await getTextToCadResult(value.id, token)
|
||||
if (check instanceof Error) {
|
||||
clearInterval(interval)
|
||||
reject(check)
|
||||
}
|
||||
const MAX_CHECK_TIMEOUT = 3 * 60_000
|
||||
const CHECK_INTERVAL = 3000
|
||||
|
||||
if (check instanceof Error || check.status === 'failed') {
|
||||
clearInterval(interval)
|
||||
reject(check)
|
||||
} else if (check.status === 'completed') {
|
||||
clearInterval(interval)
|
||||
resolve(check)
|
||||
}
|
||||
}, CHECK_INTERVAL)
|
||||
let timeElapsed = 0
|
||||
const interval = setInterval(
|
||||
toSync(async () => {
|
||||
timeElapsed += CHECK_INTERVAL
|
||||
if (timeElapsed >= MAX_CHECK_TIMEOUT) {
|
||||
clearInterval(interval)
|
||||
reject(new Error('Text-to-CAD API timed out'))
|
||||
}
|
||||
|
||||
const check = await getTextToCadResult(value.id, token)
|
||||
if (check instanceof Error) {
|
||||
clearInterval(interval)
|
||||
reject(check)
|
||||
}
|
||||
|
||||
if (check instanceof Error || check.status === 'failed') {
|
||||
clearInterval(interval)
|
||||
reject(check)
|
||||
} else if (check.status === 'completed') {
|
||||
clearInterval(interval)
|
||||
resolve(check)
|
||||
}
|
||||
}, reportRejection),
|
||||
CHECK_INTERVAL
|
||||
)
|
||||
})().catch(reportRejection)
|
||||
}
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user