Skip to content

Commit

Permalink
fix: workaround for agent-js using console warn (#86)
Browse files Browse the repository at this point in the history
* fix: workaround for agent-js using console warn

* chore: format

* chore: ignore linter
  • Loading branch information
peterpeterparker authored Feb 8, 2024
1 parent b312193 commit 695c767
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/services/upgrade-assert.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,34 @@ export const assertSatelliteBuildType = async ({
satellite,
wasm_module
}: {satellite: SatelliteParameters} & UpgradeWasmModule) => {
const [wasmType, satelliteType] = await Promise.all([
// TODO: Workaround for agent-js. Disable console.warn.
// See https://github.com/dfinity/agent-js/issues/843
// eslint-disable-next-line @typescript-eslint/unbound-method
const hideAgentJsConsoleWarn = globalThis.console.warn;
globalThis.console.warn = (): null => null;

const [wasmTypeResult, satelliteTypeResult] = await Promise.allSettled([
wasmBuildType({wasm_module}),
satelliteBuildType({
satellite
})
]);

// Redo console.warn
globalThis.console.warn = hideAgentJsConsoleWarn;

if (wasmTypeResult.status === 'rejected') {
throw new Error(`The custom sections of the WASM module you try to upgrade cannot be read.`);
}

// Agent-js throw an exception when a metadata path cannot be found therefore we assumed here that this happens because the Satellite version is < 0.0.15.
if (satelliteTypeResult.status === 'rejected') {
return;
}

const {value: wasmType} = wasmTypeResult;
const {value: satelliteType} = satelliteTypeResult;

if (satelliteType === 'extended' && (wasmType === 'stock' || isNullish(wasmType))) {
await confirmAndExit(
`Your satellite is currently running on an ${yellow(
Expand Down

0 comments on commit 695c767

Please sign in to comment.