Skip to content

Commit c36a4c8

Browse files
committed
fix(logging): add optional chaining to prevent undefined property access
Add optional chaining operators to message.usage property access in console log statements to prevent potential "Cannot read property of undefined" errors when the usage object might not exist.
1 parent a60a59b commit c36a4c8

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/commitMessageGenerator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ export class CommitMessageGenerator {
8888
return undefined
8989
} finally {
9090
console.log("[DiffCommit] Stop Reason: ", message?.stop_reason)
91-
console.log("[DiffCommit] Input Tokens: ", message?.usage.input_tokens)
92-
console.log("[DiffCommit] Cache Creation Tokens: ", message?.usage.cache_creation_input_tokens)
93-
console.log("[DiffCommit] Cache Read Tokens: ", message?.usage.cache_read_input_tokens)
94-
console.log("[DiffCommit] Output Tokens: ", message?.usage.output_tokens)
91+
console.log("[DiffCommit] Input Tokens: ", message?.usage?.input_tokens)
92+
console.log("[DiffCommit] Cache Creation Tokens: ", message?.usage?.cache_creation_input_tokens)
93+
console.log("[DiffCommit] Cache Read Tokens: ", message?.usage?.cache_read_input_tokens)
94+
console.log("[DiffCommit] Output Tokens: ", message?.usage?.output_tokens)
9595
}
9696
}
9797

0 commit comments

Comments
 (0)