Skip to content

Commit 9cbaf2a

Browse files
author
Fabrice Bascoulergue
committed
Fix log parsing for failed transactions
1 parent a1e632b commit 9cbaf2a

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/utils/txlogs.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,21 @@ export const parseLogs = (input: unknown): readonly Log[] => {
5252
* @param input transaction log (for tx returned by the client you can use tx.result.log)
5353
*/
5454
export const parseRawLogs = (input = '[]'): readonly Log[] => {
55-
const logsToParse = JSON.parse(input).map(({ events }: { events: readonly unknown[] }, i: number) => ({
56-
msg_index: i,
57-
events,
58-
log: '',
59-
}));
60-
return parseLogs(logsToParse);
55+
try {
56+
const logsToParse = JSON.parse(input).map(({ events }: { events: readonly unknown[] }, i: number) => ({
57+
msg_index: i,
58+
events,
59+
log: '',
60+
}));
61+
return parseLogs(logsToParse);
62+
} catch (e) {
63+
// Transactions that failed only contain a string error message in the logs
64+
return [
65+
{
66+
msg_index: 0,
67+
events: [],
68+
log: input,
69+
},
70+
];
71+
}
6172
};

0 commit comments

Comments
 (0)