From 1b3edad0d2ce2c91e98793c65998def8b7a51bc2 Mon Sep 17 00:00:00 2001 From: Gemini AI Date: Sun, 14 Dec 2025 00:48:56 +0400 Subject: [PATCH] Hotfix: Prevent crash on missing config.cjs & Graceful fallback --- qwen-oauth.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/qwen-oauth.js b/qwen-oauth.js index 438ef94..4583fed 100644 --- a/qwen-oauth.js +++ b/qwen-oauth.js @@ -29,12 +29,10 @@ try { // Handle both ESM and CJS exports if (config.default) config = config.default; } catch (e) { - // Fallback or error if config is missing - console.error('Error loading config:', e.message); - console.error('Error: config.cjs not found. Please copy config.example.cjs to config.cjs and add your Client ID.'); - process.exit(1); + // Config missing is expected for first-time users using CLI only. + // We don't crash here - we just run without OAuth support (CLI fallback) } -const QWEN_OAUTH_CLIENT_ID = config.QWEN_OAUTH_CLIENT_ID; +const QWEN_OAUTH_CLIENT_ID = config.QWEN_OAUTH_CLIENT_ID || null; const QWEN_OAUTH_SCOPE = 'openid profile email model.completion'; const QWEN_OAUTH_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code'; const QWEN_CHAT_API = 'https://chat.qwen.ai/api/chat/completions'; @@ -166,6 +164,10 @@ class QwenOAuth { async startDeviceFlow() { console.log('Starting Qwen Device Code Flow with PKCE...'); + if (!QWEN_OAUTH_CLIENT_ID) { + throw new Error('Missing Client ID. Please copy config.example.cjs to config.cjs and add your QWEN_OAUTH_CLIENT_ID to use this feature.'); + } + // Generate PKCE pair this.codeVerifier = generateCodeVerifier(); const codeChallenge = generateCodeChallenge(this.codeVerifier);