From 663ec8e4b9c7505150fa5b9ac255adf49aa3d591 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Mon, 13 Oct 2025 14:32:08 +0530 Subject: [PATCH] Improved error messages --- src/commands/tsgen.ts | 8 ++++---- src/lib/helper.ts | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/commands/tsgen.ts b/src/commands/tsgen.ts index 4d7b78c..34b04c2 100644 --- a/src/commands/tsgen.ts +++ b/src/commands/tsgen.ts @@ -132,12 +132,12 @@ export default class TypeScriptCodeGeneratorCommand extends Command { if (token.type !== "delivery") { this.warn( - "Possibly using a management token. You may not be able to connect to your Stack. Please use a delivery token.", + "You might be using a management token. Connection may fail. Use a delivery token instead.", ); } if (!outputPath || !outputPath.trim()) { - this.error("Please provide an output path.", { exit: 2 }); + this.error("Output path is required.", { exit: 2 }); } const config: StackConnectionConfig = { @@ -160,7 +160,7 @@ export default class TypeScriptCodeGeneratorCommand extends Command { // Check if token has delivery type (required for GraphQL) if (token.type !== "delivery") { throw new Error( - "GraphQL API requires a delivery token. Management tokens are not supported for GraphQL operations.", + "GraphQL API requires a delivery token. Management tokens aren't supported.", ); } @@ -185,7 +185,7 @@ export default class TypeScriptCodeGeneratorCommand extends Command { const result = await graphqlTS(graphqlConfig); if (!result) { - throw new Error("GraphQL API returned no result"); + throw new Error("No result returned by the GraphQL API."); } fs.writeFileSync(outputPath, result); diff --git a/src/lib/helper.ts b/src/lib/helper.ts index 566afae..bb02d2d 100644 --- a/src/lib/helper.ts +++ b/src/lib/helper.ts @@ -39,47 +39,47 @@ export const printFormattedError = (error: FormattedError, context: string) => { return; } - let errorMessage = "An unexpected error occurred"; + let errorMessage = "An unexpected error occurred. Try again."; let hint = ""; switch (errorCode) { case "AUTHENTICATION_FAILED": - errorMessage = "Authentication failed"; + errorMessage = "Authentication failed. Check your credentials and try again."; hint = "Please check your API key, token, and region."; break; case "INVALID_CREDENTIALS": - errorMessage = "Invalid credentials provided"; + errorMessage = "Invalid credentials. Please verify and re-enter your login details."; hint = "Please verify your API key, token, and region."; break; case "INVALID_INTERFACE_NAME": case "INVALID_CONTENT_TYPE_UID": - errorMessage = "TypeScript syntax error detected in the generated types."; + errorMessage = "Generated types contain a TypeScript syntax error."; hint = "Use a prefix to ensure all interface names are valid TypeScript identifiers."; break; case "INVALID_GLOBAL_FIELD_REFERENCE": - errorMessage = "TypeScript syntax error detected in the generated types."; + errorMessage = "Generated types contain a TypeScript syntax error."; hint = "Use a prefix to ensure all interface names are valid TypeScript identifiers."; break; case "VALIDATION_ERROR": - errorMessage = "TypeScript syntax error detected in generated types"; + errorMessage = "Type generation failed due to a validation error."; hint = error?.error_message || - "Validation error occurred during type generation"; + "Type generation failed due to a validation error."; break; case "TYPE_GENERATION_FAILED": - errorMessage = "Type generation failed due to an internal error"; + errorMessage = "Type generation failed due to a system error. Try again."; hint = error?.error_message || - "An unexpected error occurred during type generation"; + "Unexpected error during type generation. Try again."; break; default: errorMessage = error?.error_message || error?.message || - "An unexpected error occurred"; - hint = "Please check the error details and try again."; + "An unexpected error occurred. Try again."; + hint = "Check the error details and try again."; } // Print formatted error output