fix(terra): surface Claude usage errors and retry sooner
The CLD panel went blank with no reason when Claude Code's saved OAuth token had expired and the widget's own renewal was refused. - Collapsed panel shows EXPIRED/ERR instead of dashes; failures are logged to `qs log`. - Retry every minute after a failure instead of every 5. - claude-usage identifies as claude-cli, the suspected cause of the refresh 429s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ BarPanel {
|
||||
property var sevenDay: usage.sevenDay
|
||||
property var extra: usage.extra
|
||||
property string error: usage.error
|
||||
property string shortError: usage.shortError
|
||||
property bool ready: usage.ready
|
||||
|
||||
readonly property var usage: ClaudeState {}
|
||||
@@ -74,6 +75,8 @@ BarPanel {
|
||||
required property var modelData
|
||||
spacing: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
// Dashes say nothing; with no numbers yet the error label stands alone.
|
||||
visible: claude.ready || claude.shortError === ""
|
||||
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
@@ -93,6 +96,16 @@ BarPanel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: claude.shortError !== ""
|
||||
text: claude.shortError
|
||||
color: Theme.hot
|
||||
font.family: Theme.displayFont
|
||||
font.pixelSize: 13
|
||||
font.bold: true
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
|
||||
@@ -16,8 +16,16 @@ QtObject {
|
||||
property string error: ""
|
||||
property bool ready: false
|
||||
|
||||
// The endpoint is rate-limited and the numbers move slowly.
|
||||
property int interval: 300000
|
||||
// The endpoint is rate-limited and the numbers move slowly; a failure
|
||||
// retries sooner so the panel recovers once Claude Code renews the token.
|
||||
property int interval: root.error !== "" ? 60000 : 300000
|
||||
|
||||
// Collapsed-rail label for the current error.
|
||||
readonly property string shortError: {
|
||||
if (root.error === "")
|
||||
return "";
|
||||
return /refresh|401|not logged in|no refresh token/.test(root.error) ? "EXPIRED" : "ERR";
|
||||
}
|
||||
|
||||
readonly property var proc: Process {
|
||||
id: proc
|
||||
@@ -39,17 +47,22 @@ QtObject {
|
||||
}
|
||||
}
|
||||
|
||||
function fail(message: string): void {
|
||||
console.warn(`claude-usage: ${message}`);
|
||||
root.error = message;
|
||||
}
|
||||
|
||||
function ingest(text: string): void {
|
||||
let msg;
|
||||
try {
|
||||
msg = JSON.parse(text);
|
||||
} catch (e) {
|
||||
root.error = "no output";
|
||||
root.fail("no output");
|
||||
return;
|
||||
}
|
||||
if (msg.error) {
|
||||
// Keep the last good numbers; a failed poll is not zero usage.
|
||||
root.error = msg.error;
|
||||
root.fail(msg.error);
|
||||
return;
|
||||
}
|
||||
root.error = "";
|
||||
|
||||
Reference in New Issue
Block a user