Skip to content

Commit cb4d2de

Browse files
committed
Improve log for entity history error
1 parent 0455ccb commit cb4d2de

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
lines changed

codegenerator/cli/npm/envio/src/PgStorage.res

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,7 @@ let setEntityHistoryOrThrow = (
418418
~shouldCopyCurrentEntity=?,
419419
~shouldRemoveInvalidUtf8=false,
420420
) => {
421-
rows
422-
->Belt.Array.map(historyRow => {
421+
rows->Belt.Array.map(historyRow => {
423422
let row = historyRow->S.reverseConvertToJsonOrThrow(entityHistory.schema)
424423
if shouldRemoveInvalidUtf8 {
425424
[row]->removeInvalidUtf8InPlace
@@ -435,10 +434,19 @@ let setEntityHistoryOrThrow = (
435434
!containsRollbackDiffChange
436435
}
437436
},
438-
)
437+
)->Promise.catch(exn => {
438+
let reason = exn->Utils.prettifyExn
439+
let detail = %raw(`reason?.detail || ""`)
440+
raise(
441+
Persistence.StorageError({
442+
message: `Failed to insert history item into table "${entityHistory.table.tableName}".${detail !== ""
443+
? ` Details: ${detail}`
444+
: ""}`,
445+
reason,
446+
}),
447+
)
448+
})
439449
})
440-
->Promise.all
441-
->(Utils.magic: promise<array<unit>> => promise<unit>)
442450
}
443451

444452
type schemaTableName = {

codegenerator/cli/npm/envio/src/db/InternalTable.gen.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@
33
/* eslint-disable */
44
/* tslint:disable */
55

6-
import type { Json_t as Js_Json_t } from "../../src/Js.shim";
6+
import type {Json_t as Js_Json_t} from '../../src/Js.shim';
77

8-
import type { t as Address_t } from "../../src/Address.gen";
8+
import type {t as Address_t} from '../../src/Address.gen';
99

1010
export type EventSyncState_t = {
11-
readonly chain_id: number;
12-
readonly block_number: number;
13-
readonly log_index: number;
14-
readonly block_timestamp: number;
11+
readonly chain_id: number;
12+
readonly block_number: number;
13+
readonly log_index: number;
14+
readonly block_timestamp: number
1515
};
1616

1717
export type RawEvents_t = {
18-
readonly chain_id: number;
19-
readonly event_id: bigint;
20-
readonly event_name: string;
21-
readonly contract_name: string;
22-
readonly block_number: number;
23-
readonly log_index: number;
24-
readonly src_address: Address_t;
25-
readonly block_hash: string;
26-
readonly block_timestamp: number;
27-
readonly block_fields: Js_Json_t;
28-
readonly transaction_fields: Js_Json_t;
29-
readonly params: Js_Json_t;
18+
readonly chain_id: number;
19+
readonly event_id: bigint;
20+
readonly event_name: string;
21+
readonly contract_name: string;
22+
readonly block_number: number;
23+
readonly log_index: number;
24+
readonly src_address: Address_t;
25+
readonly block_hash: string;
26+
readonly block_timestamp: number;
27+
readonly block_fields: Js_Json_t;
28+
readonly transaction_fields: Js_Json_t;
29+
readonly params: Js_Json_t
3030
};
3131

3232
export type DynamicContractRegistry_t = {
33-
readonly id: string;
34-
readonly chain_id: number;
35-
readonly registering_event_block_number: number;
36-
readonly registering_event_log_index: number;
37-
readonly registering_event_block_timestamp: number;
38-
readonly registering_event_contract_name: string;
39-
readonly registering_event_name: string;
40-
readonly registering_event_src_address: Address_t;
41-
readonly contract_address: Address_t;
42-
readonly contract_name: string;
33+
readonly id: string;
34+
readonly chain_id: number;
35+
readonly registering_event_block_number: number;
36+
readonly registering_event_log_index: number;
37+
readonly registering_event_block_timestamp: number;
38+
readonly registering_event_contract_name: string;
39+
readonly registering_event_name: string;
40+
readonly registering_event_src_address: Address_t;
41+
readonly contract_address: Address_t;
42+
readonly contract_name: string
4343
};

codegenerator/cli/templates/static/codegen/src/IO.res

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,17 @@ let executeBatch = async (
136136
sql => {
137137
let promises = []
138138
if entityHistoryItemsToSet->Utils.Array.notEmpty {
139-
promises->Array.push(
139+
promises
140+
->Js.Array2.pushMany(
140141
sql->PgStorage.setEntityHistoryOrThrow(
141142
~entityHistory=entityConfig.entityHistory,
142-
~rows=entityHistoryItemsToSet,
143+
~rows=entityHistoryItemsToSet->Array.concat([
144+
entityHistoryItemsToSet->Js.Array2.unsafe_get(0),
145+
]),
143146
~shouldRemoveInvalidUtf8,
144147
),
145148
)
149+
->ignore
146150
}
147151
if entitiesToSet->Utils.Array.notEmpty {
148152
if shouldRemoveInvalidUtf8 {

0 commit comments

Comments
 (0)