Kaynağa Gözat

fix(cli): Reformat error logging and remove duplicates

HouseinIsProgramming 7 ay önce
ebeveyn
işleme
6e557e8758

+ 3 - 5
packages/cli/src/commands/add/add-operations.ts

@@ -1,5 +1,3 @@
-import { log } from '@clack/prompts';
-
 import { addApiExtensionCommand } from './api-extension/add-api-extension';
 import { addCodegenCommand } from './codegen/add-codegen';
 import { addEntityCommand } from './entity/add-entity';
@@ -135,9 +133,9 @@ export async function performAddOperation(options: AddOperationOptions): Promise
             message: 'No valid add operation specified',
         };
     } catch (error: any) {
-        log.error(error.message);
-        if (error.stack) {
-            log.error(error.stack);
+        // Re-throw validation errors so they can be properly handled with stack trace
+        if (error.message.includes('Plugin name is required')) {
+            throw error;
         }
         return {
             success: false,

+ 16 - 3
packages/cli/src/commands/add/add.ts

@@ -39,9 +39,22 @@ async function handleNonInteractiveMode(options: AddOperationOptions) {
             process.exit(1);
         }
     } catch (e: any) {
-        log.error(e.message as string);
-        if (e.stack) {
-            log.error(e.stack);
+        // For validation errors, show the full error with stack trace
+        if (e.message.includes('Plugin name is required')) {
+            // Extract error message and stack trace
+            const errorMessage = e.message;
+            const stackLines = e.stack.split('\n');
+            const stackTrace = stackLines.slice(1).join('\n'); // Remove first line (error message)
+
+            // Display colored error message, newline, then stack trace
+            log.error(pc.red('Error:') + ' ' + String(errorMessage));
+            log.error(''); // Add empty line for better readability
+            log.error(stackTrace);
+        } else {
+            log.error(e.message as string);
+            if (e.stack) {
+                log.error(e.stack);
+            }
         }
         process.exit(1);
     }