Browse Source

Error handling

pull/110/head
Malte Grimm 3 years ago
parent
commit
5c23711f04
  1. 10
      src/components/Dashboard.tsx
  2. 10
      src/core/flashing/Flasher.ts

10
src/components/Dashboard.tsx

@ -88,6 +88,7 @@ const DeviceList = ({devices, rootConfig, totalConfigCount}: {devices: Device[],
useState(new Array<{state: string, progress: number}>(100).fill({progress: 1, state: 'doFlash'}));//useState(devices.map(d => d.flashState));
const [ fullFlash, setFullFlash ] = useState(false);
const { getDevices } = useDeviceStore();
const { toast, toasts } = useToast();
// const [flashingState, setFlashingState]: any = useState([]);
const cancelButtonVisible = overallFlashingState.state != "idle";
const firmware = firmwareList.find(f => f.id == selectedFirmware);
@ -174,10 +175,11 @@ const DeviceList = ({devices, rootConfig, totalConfigCount}: {devices: Device[],
(f)=> {
f.device.setFlashState(f.state);
deviceSelectedToFlash[devices.indexOf(f.device)] = f.state;
setDeviceSelectedToFlash(deviceSelectedToFlash);
// flashingState[f.device.id] = f.state;
// setFlashingState(flashingState);
setDeviceSelectedToFlash(deviceSelectedToFlash);
if(f.state.state == "failed") {
toast({ title: `❌ Error: ${f.errorReason}`});
}
}
);
}}

10
src/core/flashing/Flasher.ts

@ -229,16 +229,18 @@ function autoDetectDeviceModel(port: SerialPort) {
export class FlashOperation {
public state: FlashState = { progress: 0, state: "idle" };
public errorReason?: string;
private loader?: EspLoader;
public constructor(public device: Device, public config: Protobuf.LocalConfig, public callback: (operation: FlashOperation) => void) {
}
public setState(state: DeviceFlashingState, progress = 0) {
public setState(state: DeviceFlashingState, progress = 0, errorReason : string | undefined = undefined) {
console.log(`${this.device.nodes.get(this.device.hardware.myNodeNum)?.user
?.longName ?? "<Not flashed yet>"} flash state: ${state}`);
this.state = {state, progress};
this.errorReason = errorReason;
this.callback(this);
}
@ -249,8 +251,8 @@ export class FlashOperation {
this.setState("done");
}
catch(e) {
debugger;
this.setState("failed");
this.setState("failed", 0, e as string);
throw e;
}
}
@ -295,7 +297,7 @@ export class FlashOperation {
bytesFlashed += sections[i].data.byteLength;
}
}
catch (e) {
catch (e) {
throw e;
}
finally {

Loading…
Cancel
Save