fix(cli): handle unhandled errors in execAsync

This commit is contained in:
Nicolas Meienberger 2023-09-27 19:00:10 +02:00 committed by Nicolas Meienberger
parent 7c40c7e0da
commit 163d2f9374
9 changed files with 105 additions and 2299 deletions

View file

@ -2,8 +2,6 @@
/* eslint-disable no-restricted-syntax */
import fs from 'fs';
import path from 'path';
import { exec } from 'child_process';
import { promisify } from 'util';
import pg from 'pg';
import { getEnv } from '@/utils/environment/environment';
import { pathExists } from '@/utils/fs-helpers';
@ -11,8 +9,7 @@ import { compose } from '@/utils/docker-helpers';
import { copyDataDir, generateEnvFile } from './app.helpers';
import { fileLogger } from '@/utils/logger/file-logger';
import { TerminalSpinner } from '@/utils/logger/terminal-spinner';
const execAsync = promisify(exec);
import { execAsync } from '@/utils/exec-async/execAsync';
const getDbClient = async () => {
const { postgresDatabase, postgresUsername, postgresPassword, postgresPort } = getEnv();

View file

@ -2,13 +2,10 @@ import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import { appInfoSchema, envMapToString, envStringToMap } from '@runtipi/shared';
import { exec } from 'child_process';
import { promisify } from 'util';
import { getEnv } from '@/utils/environment/environment';
import { generateVapidKeys, getAppEnvMap } from './env.helpers';
import { pathExists } from '@/utils/fs-helpers';
const execAsync = promisify(exec);
import { execAsync } from '@/utils/exec-async/execAsync';
/**
* This function generates a random string of the provided length by using the SHA-256 hash algorithm.

View file

@ -1,12 +1,9 @@
import { getEnv } from 'src/utils/environment/environment';
import path from 'path';
import { promisify } from 'util';
import { exec } from 'child_process';
import { pathExists } from '@/utils/fs-helpers';
import { getRepoHash } from './repo.helpers';
import { fileLogger } from '@/utils/logger/file-logger';
const execAsync = promisify(exec);
import { execAsync } from '@/utils/exec-async/execAsync';
export class RepoExecutors {
private readonly logger;

View file

@ -7,10 +7,9 @@ import semver from 'semver';
import axios from 'axios';
import boxen from 'boxen';
import path from 'path';
import { exec, spawn } from 'child_process';
import { spawn } from 'child_process';
import si from 'systeminformation';
import { Stream } from 'stream';
import { promisify } from 'util';
import dotenv from 'dotenv';
import { SystemEvent } from '@runtipi/shared';
import chalk from 'chalk';
@ -23,8 +22,7 @@ import { getEnv } from '@/utils/environment/environment';
import { fileLogger } from '@/utils/logger/file-logger';
import { runPostgresMigrations } from '@/utils/migrations/run-migration';
import { getUserIds } from '@/utils/environment/user';
const execAsync = promisify(exec);
import { execAsync } from '@/utils/exec-async/execAsync';
export class SystemExecutors {
private readonly rootFolder: string;

View file

@ -3,12 +3,11 @@ import fs from 'fs';
import path from 'path';
import os from 'os';
import { envMapToString, envStringToMap, settingsSchema } from '@runtipi/shared';
import { exec } from 'child_process';
import { promisify } from 'util';
import chalk from 'chalk';
import { pathExists } from '@/utils/fs-helpers';
import { getRepoHash } from '../repo/repo.helpers';
import { fileLogger } from '@/utils/logger/file-logger';
import { execAsync } from '@/utils/exec-async/execAsync';
type EnvKeys =
| 'APPS_REPO_ID'
@ -38,8 +37,6 @@ type EnvKeys =
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {});
const execAsync = promisify(exec);
const DEFAULT_REPO_URL = 'https://github.com/meienberger/runtipi-appstore';
/**

View file

@ -1,13 +1,10 @@
import { eventSchema } from '@runtipi/shared';
import { Worker } from 'bullmq';
import { exec } from 'child_process';
import { promisify } from 'util';
import { AppExecutors, RepoExecutors, SystemExecutors } from '@/executors';
import { getEnv } from '@/utils/environment/environment';
import { getUserIds } from '@/utils/environment/user';
import { fileLogger } from '@/utils/logger/file-logger';
const execAsync = promisify(exec);
import { execAsync } from '@/utils/exec-async/execAsync';
const runCommand = async (jobData: unknown) => {
const { gid, uid } = getUserIds();

View file

@ -1,11 +1,8 @@
import path from 'path';
import { promisify } from 'util';
import { exec } from 'child_process';
import { getEnv } from '../environment/environment';
import { pathExists } from '../fs-helpers/fs-helpers';
import { fileLogger } from '../logger/file-logger';
const execAsync = promisify(exec);
import { execAsync } from '../exec-async/execAsync';
const composeUp = async (args: string[]) => {
const { stdout, stderr } = await execAsync(`docker compose ${args.join(' ')}`);

View file

@ -0,0 +1,18 @@
import { exec } from 'child_process';
import { promisify } from 'util';
type ExecAsyncParams = [command: string];
type ExecResult = { stdout: string; stderr: string };
export const execAsync = async (...args: ExecAsyncParams): Promise<ExecResult> => {
try {
return await promisify(exec)(...args);
} catch (error) {
if (error instanceof Error) {
return { stderr: error.message, stdout: '' };
}
return { stderr: String(error), stdout: '' };
}
};

File diff suppressed because it is too large Load diff