Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ oclif
await oclif.flush();
process.exit(0);
})
.catch(handleError);
.catch(async (error) => {
await handleError(error);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"node": ">=20.7.0"
},
"scripts": {
"clean": "(rimraf --glob dist tsconfig.*.tsbuildinfo) | true",
"clean": "rimraf --glob 'dist' 'tsconfig*.tsbuildinfo' || true",
"compile": "tsc --build tsconfig.json",
"format": "yarn format:prettier --write",
"format:prettier": "prettier $@ '**/*.{ts,tsx,yaml,yml,json,md,mdx}'",
Expand Down
4 changes: 3 additions & 1 deletion src/lib/basecommands/ExecRenderBaseCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export abstract class ExecRenderBaseCommand<
const result = await this.exec();
const wrappedRender = wrapRender(this.render.bind(this));

render(
const handle = render(
<RenderContextProvider
value={{
apiClient: this.apiClient,
Expand All @@ -46,6 +46,8 @@ export abstract class ExecRenderBaseCommand<
</Suspense>
</RenderContextProvider>,
);

await handle.waitUntilExit();
}

protected abstract render(executionResult: TRes): ReactNode;
Expand Down
7 changes: 5 additions & 2 deletions src/lib/basecommands/RenderBaseCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ export abstract class RenderBaseCommand<

public async run(): Promise<void> {
const onError = () => {
setImmediate(() => {
setImmediate(async () => {
handle.unmount();
process.exit(1);
import("@oclif/core").then(async (oclif) => {
await oclif.default.flush();
process.exit(1);
});
});
};

Expand Down
10 changes: 7 additions & 3 deletions src/lib/error/handleError.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import oclif from "@oclif/core";
import { OclifError, PrettyPrintableError } from "@oclif/core/interfaces";
import { ApiClientError, AxiosResponse } from "@mittwald/api-client-commons";
import type { MittwaldAPIV2 } from "@mittwald/api-client";
Expand All @@ -8,22 +9,25 @@ type CommonsValidationErrors =
MittwaldAPIV2.Components.Schemas.CommonsValidationErrors;

// noinspection JSUnusedGlobalSymbols
export default function handleError(
export default async function handleError(
error: Error &
Partial<PrettyPrintableError> &
Partial<OclifError> & {
skipOclifErrorHandling?: boolean;
},
): void {
): Promise<void> {
if (!isUnexpectedError(error)) {
await oclif.flush();
process.exit(1);
}

if (error instanceof ExitError) {
await oclif.flush();
process.exit(error.oclif.exit);
}

renderError(error);
await renderError(error);
await oclif.flush();
process.exit(1);
}

Expand Down
5 changes: 3 additions & 2 deletions src/rendering/react/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ErrorBox } from "./components/ErrorBox.js";
* @param err The error to render. May be anything; the ErrorBox component will
* handle it.
*/
export function renderError(err: unknown) {
render(<ErrorBox err={err} />);
export async function renderError(err: unknown): Promise<void> {
const handle = render(<ErrorBox err={err} />);
await handle.waitUntilExit();
}