зеркало из https://github.com/microsoft/jacdac-ts.git
fix: throw timeout error in pipes
This commit is contained in:
Родитель
05e1003726
Коммит
8972f76b5a
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
ERROR_NO_ACK,
|
||||
ERROR_TIMEOUT,
|
||||
ERROR_TRANSPORT_DEVICE_LOCKED,
|
||||
JACDAC_ERROR,
|
||||
} from "./constants"
|
||||
|
@ -43,6 +44,10 @@ export function isAckError(e: Error) {
|
|||
return isCodeError(e, ERROR_NO_ACK)
|
||||
}
|
||||
|
||||
export function isTimeoutError(e: Error) {
|
||||
return isCodeError(e, ERROR_TIMEOUT)
|
||||
}
|
||||
|
||||
export function isCodeError(e: Error, code: string) {
|
||||
return errorCode(e) === code
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
PACKET_RECEIVE,
|
||||
DATA,
|
||||
CLOSE,
|
||||
ERROR_TIMEOUT,
|
||||
} from "./constants"
|
||||
import { Packet } from "./packet"
|
||||
import { JDBus } from "./bus"
|
||||
|
@ -242,7 +243,10 @@ export class InPipeReader extends InPipe {
|
|||
|
||||
async readAll(timeout = 500) {
|
||||
const res = await this.bus.withTimeout(timeout, this.done.signalled)
|
||||
if (!res) throw new Error("Timeout reading pipe: " + timeout + "ms")
|
||||
if (!res)
|
||||
throwError("Timeout reading pipe: " + timeout + "ms", {
|
||||
code: ERROR_TIMEOUT,
|
||||
})
|
||||
return {
|
||||
meta: this.meta,
|
||||
output: this.output,
|
||||
|
|
|
@ -11,8 +11,8 @@ import {
|
|||
read32,
|
||||
bufferToString,
|
||||
} from "../utils"
|
||||
import { HF2_TIMEOUT, ERROR_TIMEOUT } from "../constants"
|
||||
import { errorCode, throwError } from "../error"
|
||||
import { HF2_TIMEOUT } from "../constants"
|
||||
import { isTimeoutError, throwError } from "../error"
|
||||
|
||||
// see https://github.com/microsoft/uf2/blob/main/hf2.md for full spec
|
||||
export const HF2_DEVICE_MAJOR = 42
|
||||
|
@ -214,8 +214,7 @@ export class HF2Proto implements Proto {
|
|||
.catch(e => {
|
||||
console.debug(`hf2 error: ${e.message}; cmd=${cmd}`)
|
||||
if (this.io) {
|
||||
const code = errorCode(e)
|
||||
if (code !== ERROR_TIMEOUT) this.error(e)
|
||||
if (!isTimeoutError(e)) this.error(e)
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
|
|
@ -193,7 +193,7 @@ export class PromiseBuffer<T> {
|
|||
if (idx >= 0) {
|
||||
this.waiting.splice(idx, 1)
|
||||
reject(
|
||||
new JDError("Timeout", {
|
||||
new JDError(`Timeout (${timeout}ms)`, {
|
||||
code: ERROR_TIMEOUT,
|
||||
})
|
||||
)
|
||||
|
|
Загрузка…
Ссылка в новой задаче