731e297147
<img width="1418" height="804" alt="image" src="https://github.com/user-attachments/assets/de6c8222-6496-4a71-bc21-7e5e1269d5cb" /> --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com> Co-authored-by: Félix Malfait <felix@twenty.com>
19 lines
436 B
TypeScript
19 lines
436 B
TypeScript
import { type CommandResult } from '@/cli/types';
|
|
|
|
export const runSafe = async <T>(
|
|
operation: () => Promise<CommandResult<T>>,
|
|
fallbackErrorCode: string,
|
|
): Promise<CommandResult<T>> => {
|
|
try {
|
|
return await operation();
|
|
} catch (error) {
|
|
return {
|
|
success: false,
|
|
error: {
|
|
code: fallbackErrorCode,
|
|
message: error instanceof Error ? error.message : 'Unexpected error',
|
|
},
|
|
};
|
|
}
|
|
};
|