Skip to content

Commit 73cdeb8

Browse files
committed
🐛 Add debug configuration to show verbosal information in output channel
1 parent c1d9f02 commit 73cdeb8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
"default": "",
6666
"description": "Path to gptcommit executable."
6767
},
68+
"gptcommit.debug": {
69+
"type": "boolean",
70+
"default": false,
71+
"description": "If true, debug information will be shown in the output channel."
72+
},
6873
"gptcommit.expressMode": {
6974
"type": "boolean",
7075
"default": false,

src/utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,19 @@ export async function getCommitMessage(
5656
try { unlinkSync(tmpDiffFile); } catch (e) {}
5757

5858
if (/: not found\s*$/.test(stderr)) {
59+
if (config.debug) {
60+
channel.appendLine('DEBUG: gptcommit not found');
61+
}
5962
reject('gptcommit not found, see https://github.com/zurawiki/gptcommit. If it is not in your PATH, set "gptcommit.gptcommitPath" in your settings to the path to gptcommit');
6063
} else if (/OpenAI API key not found/.test(stderr)) {
64+
if (config.debug) {
65+
channel.appendLine('DEBUG: OpenAI API key not set');
66+
}
6167
reject('OpenAI API key not found, run "gptcommit.setupOpenAIApiKey" command to set it up');
6268
} else if (/is being amended/.test(stdout)) {
69+
if (config.debug) {
70+
channel.appendLine('DEBUG: allow_amend is false');
71+
}
6372
// set allow-amend to true
6473
const cmd = `${gptcommit} config set allow_amend true`;
6574
channel.appendLine(`COMMAND: ${cmd}`);
@@ -71,15 +80,27 @@ export async function getCommitMessage(
7180
reject(err);
7281
});
7382
} else if (err || stderr) {
83+
if (config.debug) {
84+
channel.appendLine(`DEBUG: gptcommit failed with error: ${err} | ${stderr}`);
85+
}
7486
try { unlinkSync(tmpMsgFile); } catch (e) {}
7587
reject(err || stderr);
7688
} else if (!existsSync(tmpMsgFile)) {
89+
if (config.debug) {
90+
channel.appendLine('DEBUG: gptcommit failed to generate commit message, message file not generated');
91+
}
7792
reject('Failed to generate commit message');
7893
} else if (config.expressMode) {
94+
if (config.debug) {
95+
channel.appendLine('DEBUG: express mode enabled, skipping editor');
96+
}
7997
const msg = readFileSync(tmpMsgFile, 'utf8');
8098
try { unlinkSync(tmpMsgFile); } catch (e) {}
8199
resolve(polishMessage(msg, config.expressModeContent));
82100
} else {
101+
if (config.debug) {
102+
channel.appendLine('DEBUG: opening editor');
103+
}
83104
const editor = vscode.window.activeTextEditor;
84105
vscode.workspace.openTextDocument(tmpMsgFile).then(async (doc) => {
85106
await vscode.window.showTextDocument(doc, {

0 commit comments

Comments
 (0)