Skip to content

Commit 3962329

Browse files
committed
add error logger
1 parent 47815b1 commit 3962329

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/core/src/parsing.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ If {{agentName}} is talking too much, you can choose [IGNORE]
1212
Your response must include one of the options.`;
1313

1414
export const parseShouldRespondFromText = (
15-
text: string
15+
text: string,
1616
): "RESPOND" | "IGNORE" | "STOP" | null => {
1717
const match = text
1818
.split("\n")[0]
@@ -92,6 +92,7 @@ export function parseJsonArrayFromText(text: string) {
9292
jsonData = JSON.parse(normalizedJson);
9393
} catch (e) {
9494
console.error("Error parsing JSON:", e);
95+
console.error("Text is not JSON", text);
9596
}
9697
}
9798

@@ -106,6 +107,7 @@ export function parseJsonArrayFromText(text: string) {
106107
const normalizedJson = arrayMatch[0].replace(/'/g, '"');
107108
jsonData = JSON.parse(normalizedJson);
108109
} catch (e) {
110+
console.error("Text is not JSON", text);
109111
console.error("Error parsing JSON:", e);
110112
}
111113
}
@@ -129,7 +131,7 @@ export function parseJsonArrayFromText(text: string) {
129131
* @returns An object parsed from the JSON string if successful; otherwise, null or the result of parsing an array.
130132
*/
131133
export function parseJSONObjectFromText(
132-
text: string
134+
text: string,
133135
): Record<string, any> | null {
134136
let jsonData = null;
135137

@@ -140,6 +142,7 @@ export function parseJSONObjectFromText(
140142
jsonData = JSON.parse(jsonBlockMatch[1]);
141143
} catch (e) {
142144
console.error("Error parsing JSON:", e);
145+
console.error("Text is not JSON", text);
143146
return null;
144147
}
145148
} else {
@@ -151,6 +154,7 @@ export function parseJSONObjectFromText(
151154
jsonData = JSON.parse(objectMatch[0]);
152155
} catch (e) {
153156
console.error("Error parsing JSON:", e);
157+
console.error("Text is not JSON", text);
154158
return null;
155159
}
156160
}
@@ -172,7 +176,7 @@ export function parseJSONObjectFromText(
172176
export const postActionResponseFooter = `Choose any combination of [LIKE], [RETWEET], [QUOTE], and [REPLY] that are appropriate. Each action must be on its own line. Your response must only include the chosen actions.`;
173177

174178
export const parseActionResponseFromText = (
175-
text: string
179+
text: string,
176180
): { actions: ActionResponse } => {
177181
const actions: ActionResponse = {
178182
like: false,
@@ -211,7 +215,7 @@ export const parseActionResponseFromText = (
211215
*/
212216
export function truncateToCompleteSentence(
213217
text: string,
214-
maxLength: number
218+
maxLength: number,
215219
): string {
216220
if (text.length <= maxLength) {
217221
return text;

0 commit comments

Comments
 (0)