Skip to content

Commit

Permalink
meta: added catch for uncaught async promises for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
2hwk authored and aguther committed Sep 30, 2021
1 parent 23eb024 commit 7a5c6d9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class A320_Neo_CDU_AirwaysFromWaypointPage {
mcdu.onLeftInput[i] = async (value) => {
if (value.length > 0) {
mcdu.ensureCurrentFlightPlanIsTemporary(async () => {
const airway = await this._getAirway(mcdu, value);
const airway = await this._getAirway(mcdu, value).catch(console.error);
if (airway) {
A320_Neo_CDU_AirwaysFromWaypointPage.ShowPage(mcdu, waypoint, offset, airway);
} else {
Expand All @@ -68,7 +68,7 @@ class A320_Neo_CDU_AirwaysFromWaypointPage {
} else {
mcdu.addNewMessage(NXSystemMessages.awyWptMismatch);
}
});
}).catch(console.error);
});
}
};
Expand All @@ -77,12 +77,12 @@ class A320_Neo_CDU_AirwaysFromWaypointPage {
subRows[i + 1] = ["\xa0VIA", ""];
mcdu.onLeftInput[i + 1] = async (value) => {
if (value.length > 0) {
const toWp = await this._getFirstIntersection(mcdu.flightPlanManager, value, pendingAirway.icaos);
const toWp = await this._getFirstIntersection(mcdu.flightPlanManager, value, pendingAirway.icaos).catch(console.error);
if (toWp) {
mcdu.ensureCurrentFlightPlanIsTemporary(() => {
mcdu.insertWaypointsAlongAirway(toWp, mcdu.flightPlanManager.getEnRouteWaypointsLastIndex() + 1, pendingAirway.name, async (result) => {
if (result) {
const airway = await this._getAirway(mcdu, value);
const airway = await this._getAirway(mcdu, value).catch(console.error);
if (airway) {
A320_Neo_CDU_AirwaysFromWaypointPage.ShowPage(mcdu, waypoint, offset, airway);
} else {
Expand All @@ -91,7 +91,7 @@ class A320_Neo_CDU_AirwaysFromWaypointPage {
} else {
mcdu.addNewMessage(NXSystemMessages.noIntersectionFound);
}
});
}).catch(console.error);
});
} else {
mcdu.addNewMessage(NXSystemMessages.noIntersectionFound);
Expand Down Expand Up @@ -171,14 +171,14 @@ class A320_Neo_CDU_AirwaysFromWaypointPage {
const ident = fpm.getWaypoints()[fpm.getEnRouteWaypointsLastIndex()].ident;
const identIdx = icaos.findIndex(x => x.substring(4).trim() === ident);
for (let i = 0; i < icaos.length - identIdx; i++) {
let res = await this._getRoute(fpm, value, icaos[identIdx + i]);
let res = await this._getRoute(fpm, value, icaos[identIdx + i]).catch(console.error);
if (res) {
return icaos[identIdx + i].substring(4).trim();
}
if (identIdx - i < 0 || i === 0) {
continue;
}
res = await this._getRoute(fpm, value, icaos[identIdx - i]);
res = await this._getRoute(fpm, value, icaos[identIdx - i]).catch(console.error);
if (res) {
return icaos[identIdx - i].substring(4).trim();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class CDUAvailableDeparturesPage {
mcdu.onRightInput[i + 1] = () => {
mcdu.flightPlanManager.setDepartureEnRouteTransitionIndex(enRouteTransitionIndex, () => {
CDUAvailableDeparturesPage.ShowPage(mcdu, airport, 0, true);
});
}).catch(console.error);
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class FMCMainDisplay extends BaseAirliners {
};
const arrivalIndex = this.flightPlanManager.getArrivalProcIndex();
if (arrivalIndex >= 0) {
this.flightPlanManager.setArrivalProcIndex(arrivalIndex, callback);
this.flightPlanManager.setArrivalProcIndex(arrivalIndex, callback).catch(console.error);
} else {
callback();
}
Expand Down Expand Up @@ -1661,8 +1661,8 @@ class FMCMainDisplay extends BaseAirliners {
this.flightPlanManager.setDepartureProcIndex(-1, () => {
this.flightPlanManager.setOriginRunwayIndex(runwayIndex, () => {
return callback(true);
});
});
}).catch(console.error);
}).catch(console.error);
});
}

Expand All @@ -1677,13 +1677,13 @@ class FMCMainDisplay extends BaseAirliners {
this.flightPlanManager.setDepartureRunwayIndex(-1, () => {
this.flightPlanManager.setOriginRunwayIndex(-1, () => {
return callback(true);
});
});
}).catch(console.error);
}).catch(console.error);
} else if (routeOriginInfo instanceof AirportInfo) {
if (routeOriginInfo.oneWayRunways[runwayIndex]) {
this.flightPlanManager.setDepartureRunwayIndex(runwayIndex, () => {
return callback(true);
});
}).catch(console.error);
}
} else {
this.addNewMessage(NXSystemMessages.notInDatabase);
Expand All @@ -1704,48 +1704,48 @@ class FMCMainDisplay extends BaseAirliners {
if (departureRunwayIndex >= -1) {
return this.flightPlanManager.setDepartureRunwayIndex(departureRunwayIndex, () => {
return callback(true);
});
}).catch(console.error);
}
}
return callback(true);
});
}).catch(console.error);
});
}

setApproachTransitionIndex(transitionIndex, callback = EmptyCallback.Boolean) {
console.log("FMCMainDisplay: setApproachTransitionIndex = ", transitionIndex);
//console.log("FMCMainDisplay: setApproachTransitionIndex = ", transitionIndex);
const arrivalIndex = this.flightPlanManager.getArrivalProcIndex();
this.ensureCurrentFlightPlanIsTemporary(() => {
this.flightPlanManager.setApproachTransitionIndex(transitionIndex, () => {
this.flightPlanManager.setArrivalProcIndex(arrivalIndex, () => {
callback(true);
});
});
}).catch(console.error);
}).catch(console.error);
});
}

setArrivalProcIndex(arrivalIndex, callback = EmptyCallback.Boolean) {
console.log("FMCMainDisplay: setArrivalProcIndex = ", arrivalIndex);
//console.log("FMCMainDisplay: setArrivalProcIndex = ", arrivalIndex);
this.ensureCurrentFlightPlanIsTemporary(() => {
this.flightPlanManager.setArrivalProcIndex(arrivalIndex, () => {
callback(true);
});
}).catch(console.error);
});
}

setArrivalIndex(arrivalIndex, transitionIndex, callback = EmptyCallback.Boolean) {
console.log("FMCMainDisplay: setArrivalIndex: arrivalIndex=", arrivalIndex, " transitionIndex=", transitionIndex);
//console.log("FMCMainDisplay: setArrivalIndex: arrivalIndex=", arrivalIndex, " transitionIndex=", transitionIndex);
this.ensureCurrentFlightPlanIsTemporary(() => {
this.flightPlanManager.setArrivalEnRouteTransitionIndex(transitionIndex, () => {
this.flightPlanManager.setArrivalProcIndex(arrivalIndex, () => {
callback(true);
});
});
}).catch(console.error);
}).catch(console.error);
});
}

setApproachIndex(approachIndex, callback = EmptyCallback.Boolean) {
console.log("FMCMainDisplay: setApproachIndex = ", approachIndex);
//console.log("FMCMainDisplay: setApproachIndex = ", approachIndex);
this.ensureCurrentFlightPlanIsTemporary(() => {
this.flightPlanManager.setApproachIndex(approachIndex, () => {
const approach = this.flightPlanManager.getApproach();
Expand All @@ -1757,7 +1757,7 @@ class FMCMainDisplay extends BaseAirliners {
}
this.clearAutotunedIls();
callback(true);
});
}).catch(console.error);
});
}

Expand Down Expand Up @@ -2003,7 +2003,7 @@ class FMCMainDisplay extends BaseAirliners {
});
};

await syncInsertWaypointByIcao(airway.icaos[firstIndex + i * inc], index + i);
await syncInsertWaypointByIcao(airway.icaos[firstIndex + i * inc], index + i).catch(console.error);
}
callback(true);
return;
Expand Down Expand Up @@ -2109,7 +2109,7 @@ class FMCMainDisplay extends BaseAirliners {
this.flightPlanManager.setDestination(airportTo.icao, () => {
this.tmpOrigin = airportTo.ident;
callback(true);
});
}).catch(console.error);
});
} else {
this.addNewMessage(NXSystemMessages.notInDatabase);
Expand Down
4 changes: 2 additions & 2 deletions src/fmgc/src/flightplanning/FlightPlanManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ export class FlightPlanManager {

if (currentFlightPlan.procedureDetails.departureIndex !== index) {
currentFlightPlan.procedureDetails.departureIndex = index;
await currentFlightPlan.buildDeparture();
await currentFlightPlan.buildDeparture().catch(console.error);

this._updateFlightPlanVersion().catch(console.error);
}
Expand All @@ -1084,7 +1084,7 @@ export class FlightPlanManager {

if (currentFlightPlan.procedureDetails.departureRunwayIndex !== index) {
currentFlightPlan.procedureDetails.departureRunwayIndex = index;
await currentFlightPlan.buildDeparture();
await currentFlightPlan.buildDeparture().catch(console.error);

this._updateFlightPlanVersion().catch(console.error);
}
Expand Down

0 comments on commit 7a5c6d9

Please sign in to comment.