Skip to content

Commit

Permalink
make withConfig async again
Browse files Browse the repository at this point in the history
  • Loading branch information
nedsalk committed Jan 13, 2025
1 parent dd84b63 commit 7c333c9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/fuels/src/cli/commands/dev/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('dev', () => {

const withConfigErrorHandler = vi
.spyOn(withConfigMod, 'withConfigErrorHandler')
.mockReturnValue(undefined as never);
.mockReturnValue(Promise.resolve());

const loadConfig = vi
.spyOn(loadConfigMod, 'loadConfig')
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/src/cli/commands/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const configFileChanged = (state: DevState) => async (_event: string, pat
// eslint-disable-next-line @typescript-eslint/no-use-before-define
await dev(await loadConfig(state.config.basePath));
} catch (err: unknown) {
withConfigErrorHandler(<Error>err, state.config);
await withConfigErrorHandler(<Error>err, state.config);
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/src/cli/commands/node/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('node', () => {

const withConfigErrorHandler = vi
.spyOn(withConfigMod, 'withConfigErrorHandler')
.mockReturnValue(undefined as never);
.mockReturnValue(Promise.resolve());

const loadConfig = vi
.spyOn(loadConfigMod, 'loadConfig')
Expand Down
8 changes: 4 additions & 4 deletions packages/fuels/src/cli/commands/withConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { loadConfig } from '../config/loadConfig';
import type { Commands, FuelsConfig, CommandEvent } from '../types';
import { error, log } from '../utils/logger';

export const withConfigErrorHandler = (err: Error, config?: FuelsConfig) => {
export const withConfigErrorHandler = async (err: Error, config?: FuelsConfig): Promise<void> => {
error(err.message);
config?.onFailure?.(config, <Error>err);
await config?.onFailure?.(config, <Error>err);
throw err;
};

Expand All @@ -27,15 +27,15 @@ export function withConfig<CType extends Commands>(
try {
config = await loadConfig(options.path);
} catch (err) {
withConfigErrorHandler(<Error>err);
await withConfigErrorHandler(<Error>err);
return;
}

try {
await fn(config, program);
log(`🎉 ${capitalizeString(command)} completed successfully!`);
} catch (err: unknown) {
withConfigErrorHandler(<Error>err, config);
await withConfigErrorHandler(<Error>err, config);
}
};
}

0 comments on commit 7c333c9

Please sign in to comment.