Skip to content

Commit

Permalink
Add error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Sep 17, 2024
1 parent 8af82f2 commit f5ed831
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions core/src/PTPDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ export class PTPDevice extends EventEmitter<EventTypes> {
expectedTransactionId: number,
maxByteLength: number
): Promise<BulkInInfo> {
if (!this.usb || !this.usb.opened) throw new Error()
if (!this.usb || !this.usb.opened) {
throw new Error('Device is not opened')
}

const {data, status} = await this.usb.transferIn(
this.#endpointNumberBulkIn,
Expand Down Expand Up @@ -491,7 +493,9 @@ export class PTPDevice extends EventEmitter<EventTypes> {
}

private listenInterruptIn = async () => {
if (!this.usb || !this.usb.opened) return
if (!this.usb || !this.usb.opened) {
throw new Error('Device is not opened')
}

try {
const {data, status} = await this.usb.transferIn(
Expand Down
10 changes: 7 additions & 3 deletions core/src/TethrPTPUSB/TethrSigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class TethrSigma extends TethrPTPUSB {
const fMin = minBy(apertures, a => Math.abs(a - fMinRaw))
const fMax = minBy(apertures, a => Math.abs(a - fMaxRaw))

if (!fMin || !fMax) throw new Error()
if (!fMin || !fMax) throw new Error('Invalid aperture range')

const values = apertures.filter(a => fMin <= a && a <= fMax)

Expand Down Expand Up @@ -619,7 +619,9 @@ export class TethrSigma extends TethrPTPUSB {
thirds = match2[2] === '1/3' ? 1 : 2
}

if (!match1 && !match2) throw new Error()
if (!match1 && !match2) {
throw new Error(`Cannot parse ${v} as exposure compensation`)
}

return (negative ? -1 : 1) * (digits + thirds / 3)
}
Expand Down Expand Up @@ -1074,7 +1076,9 @@ export class TethrSigma extends TethrPTPUSB {
Math.abs(computeShutterSpeedSeconds(e[1]) - ssMaxRaw)
)

if (!ssMinEntry || !ssMaxEntry) throw new Error()
if (!ssMinEntry || !ssMaxEntry) {
throw new Error('Invalid shutter speed range')
}

const ssMinIndex = ssMinEntry[0]
const ssMaxIndex = ssMaxEntry[0]
Expand Down

0 comments on commit f5ed831

Please sign in to comment.