Skip to content

Commit a6db80d

Browse files
committed
refactor: adding correct tags and names to errors
1 parent d09e92d commit a6db80d

29 files changed

+108
-63
lines changed

indexer/src/config/migrator-wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async function isDatabaseAlreadyCreated() {
7373
try {
7474
await migrate();
7575
} catch (error) {
76-
console.error('Migration failed:', error);
76+
console.error('[ERROR][INFRA][INFRA_DEPLOY] Migration failed:', error);
7777
process.exit(1);
7878
} finally {
7979
await sequelize.close();

indexer/src/kadena-server/domain/gas/input-checker.gas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ export function determineInputType(input: IGasLimitEstimationInput): UserInput {
101101

102102
// If none of the above formats match, throw error
103103
throw new GasLimitEstimationError(
104-
'Unknown input type. Please see the README for the accepted input format.',
104+
'[ERROR][GRAPHQL][GAS][INPUT_CHECKER] Unknown input type. Please see the README for the accepted input format.',
105105
);
106106
}

indexer/src/kadena-server/domain/gas/parser.gas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function parseInput(input: string): IGasLimitEstimationInput {
5353
return schema.parse(parsed);
5454
} catch (e) {
5555
throw new GasLimitEstimationError(
56-
'Unable to parse input as JSON. Please see the README for the accepted input format.',
56+
'[ERROR][GAS][PARSER] Unable to parse input as JSON. Please see the README for the accepted input format.',
5757
);
5858
}
5959
}

indexer/src/kadena-server/domain/gas/transaction.gas.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export const buildTransactionPayload = (input: UserInput, networkId: string): IU
135135

136136
// Handle unexpected input types
137137
default:
138-
throw new GasLimitEstimationError('Something went wrong generating the transaction.');
138+
throw new GasLimitEstimationError(
139+
'[ERROR][GAS][TRANSACTION] Something went wrong generating the transaction.',
140+
);
139141
}
140142

141143
return transaction;

indexer/src/kadena-server/repository/infra/gateway/gas-api-gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class GasApiGateway implements GasGateway {
8181
} catch (error) {
8282
// Wrap and rethrow any errors in our custom error type
8383
throw new GasLimitEstimationError(
84-
'Chainweb Node was unable to estimate the gas limit',
84+
'[ERROR][GAS_API_GATEWAY][ESTIMATE_GAS] Chainweb Node was unable to estimate the gas limit',
8585
error,
8686
);
8787
}

indexer/src/kadena-server/repository/infra/query-builders/transaction-query-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class TransactionQueryBuilder {
5757

5858
if (isNullOrUndefined(accountName) && minHeight && !maxHeight) {
5959
if (minHeight < 0) {
60-
throw new Error('minHeight cannot be less than 0');
60+
throw new Error('[ERROR][VALID][VALID_RANGE] minHeight cannot be less than 0');
6161
}
6262
blockParams.push(minHeight);
6363
const op = this.operator(blockParams.length);
@@ -66,7 +66,7 @@ export default class TransactionQueryBuilder {
6666

6767
if (isNullOrUndefined(accountName) && minHeight && maxHeight) {
6868
if (minHeight > maxHeight) {
69-
throw new Error('minHeight cannot be greater than maxHeight');
69+
throw new Error('[ERROR][VALID][VALID_RANGE] minHeight cannot be greater than maxHeight');
7070
}
7171

7272
blockParams.push(minHeight);

indexer/src/kadena-server/repository/infra/repository/block-db-repository.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export default class BlockDbRepository implements BlockRepository {
118118
lastHeight = parseInt(heightStr, 10);
119119
lastId = parseInt(idStr, 10);
120120
if (isNaN(lastHeight) || isNaN(lastId)) {
121-
throw new Error(`[INFO][PAGINATION][INVALID_AFTER_CURSOR] Invalid 'after' cursor:', ${after}`);
121+
throw new Error(`[ERROR][VALID][VALID_FORMAT] Invalid 'after' cursor:', ${after}`);
122122
}
123123
}
124124

@@ -127,7 +127,7 @@ export default class BlockDbRepository implements BlockRepository {
127127
lastHeight = parseInt(heightStr, 10);
128128
lastId = parseInt(idStr, 10);
129129
if (isNaN(lastHeight) || isNaN(lastId)) {
130-
throw new Error(`[INFO][PAGINATION][INVALID_BEFORE_CURSOR] Invalid 'before' cursor:', ${before}`);
130+
throw new Error(`[ERROR][VALID][VALID_FORMAT] Invalid 'before' cursor:', ${before}`);
131131
}
132132
}
133133

@@ -240,7 +240,7 @@ export default class BlockDbRepository implements BlockRepository {
240240
const beforeId = parseInt(id, 10);
241241

242242
if (isNaN(beforeHeight) || isNaN(beforeId)) {
243-
throw new Error(`[ERROR][PAGINATION][INVALID_BEFORE_CURSOR] Invalid 'before' cursor:', ${before}`);
243+
throw new Error(`[ERROR][VALID][VALID_FORMAT] Invalid 'before' cursor:', ${before}`);
244244
}
245245

246246
queryParams.push(beforeHeight, beforeId);
@@ -254,7 +254,7 @@ export default class BlockDbRepository implements BlockRepository {
254254
const afterId = parseInt(id, 10);
255255

256256
if (isNaN(afterHeight) || isNaN(afterId)) {
257-
throw new Error(`[ERROR][PAGINATION][INVALID_BEFORE_CURSOR] Invalid 'before' cursor:', ${before}`);
257+
throw new Error(`[ERROR][VALID][VALID_FORMAT] Invalid 'after' cursor:', ${after}`);
258258
}
259259
queryParams.push(afterHeight, afterId);
260260
conditions += `\nAND (b.height, b.id) < ($${queryParams.length - 1}, $${queryParams.length})`;
@@ -339,7 +339,9 @@ export default class BlockDbRepository implements BlockRepository {
339339
const [balanceRow] = balanceRows;
340340

341341
if (!balanceRow) {
342-
throw new Error(`[ERROR][MINER][NOT_FOUND] Miner account not found for block ${hash} on chain ${chainId}.`);
342+
throw new Error(
343+
`[ERROR][DB][DATA_MISSING] Miner account not found for block ${hash} on chain ${chainId}.`,
344+
);
343345
}
344346

345347
const res = await handleSingleQuery({
@@ -539,7 +541,9 @@ export default class BlockDbRepository implements BlockRepository {
539541
);
540542

541543
if (blockRows.length !== eventIds.length) {
542-
throw new Error(`[ERROR][EVENTS][FETCH_BLOCKS_MISMATCH] Fetched blocks count (${blockRows.length}) does not match event IDs count (${eventIds.length}).`);
544+
throw new Error(
545+
`[ERROR][DB][DATA_CORRUPT] Fetched blocks count (${blockRows.length}) does not match event IDs count (${eventIds.length}).`,
546+
);
543547
}
544548

545549
const blockMap = blockRows.reduce(
@@ -589,7 +593,9 @@ export default class BlockDbRepository implements BlockRepository {
589593
);
590594

591595
if (blockRows.length !== transactionIds.length) {
592-
throw new Error(`[ERROR][TRANSACTIONS][FETCH_BLOCKS_MISMATCH] Fetched blocks count (${blockRows.length}) does not match transaction IDs count (${transactionIds.length}).`);
596+
throw new Error(
597+
`[ERROR][DB][DATA_CORRUPT] Fetched blocks count (${blockRows.length}) does not match transaction IDs count (${transactionIds.length}).`,
598+
);
593599
}
594600

595601
const blockMap = blockRows.reduce(
@@ -637,7 +643,9 @@ export default class BlockDbRepository implements BlockRepository {
637643
);
638644

639645
if (blockRows.length !== hashes.length) {
640-
throw new Error(`[ERROR][BLOCKS][FETCH_BY_HASHES_MISMATCH] Fetched blocks count (${blockRows.length}) does not match requested hashes count (${hashes.length}).`);
646+
throw new Error(
647+
`[ERROR][DB][DATA_CORRUPT] Fetched blocks count (${blockRows.length}) does not match requested hashes count (${hashes.length}).`,
648+
);
641649
}
642650

643651
const blockMap = blockRows.reduce(

indexer/src/kadena-server/repository/infra/repository/pool-db-repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export default class PoolDbRepository {
169169
});
170170

171171
if (!pairResult) {
172-
throw new Error(`Token pair not found for pool ${id}`);
172+
throw new Error(`[ERROR][GRAPHQL][DB][DATA_MISSING] Token pair not found for pool ${id}`);
173173
}
174174
const pair = pairResult as Pair;
175175

@@ -188,7 +188,7 @@ export default class PoolDbRepository {
188188
const token0 = tokens.find((t: any) => t.id === pair.token0Id) as TokenModel;
189189
const token1 = tokens.find((t: any) => t.id === pair.token1Id) as TokenModel;
190190
if (!token0 || !token1) {
191-
throw new Error(`Tokens not found for pool ${id}`);
191+
throw new Error(`[ERROR][GRAPHQL][DB][DATA_MISSING] Tokens not found for pool ${id}`);
192192
}
193193

194194
// Get the latest pool stats

indexer/src/kadena-server/repository/infra/repository/transaction-db-repository.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,9 @@ export default class TransactionDbRepository implements TransactionRepository {
719719
);
720720

721721
if (rows.length !== eventIds.length) {
722-
throw new Error(`[ERROR][EVENTS][FETCH_BLOCKS_MISMATCH] Fetched blocks count (${rows.length}) does not match event IDs count (${eventIds.length}).`);
722+
throw new Error(
723+
`[ERROR][DB][DATA_CORRUPT] Fetched blocks count (${rows.length}) does not match event IDs count (${eventIds.length}).`,
724+
);
723725
}
724726

725727
const transactionMap = rows.reduce(

indexer/src/kadena-server/resolvers/node-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const getNode = async (context: ResolverContext, id: string) => {
6161
// TODO: [ERROR-OPTIMIZATION] missing try catch block
6262
const output = await context.blockRepository.getBlockByHash(params);
6363
if (!output) {
64-
throw new Error('[ERROR][DB][DATA_MISSING] Block not found.');
64+
throw new Error('[ERROR][GRAPHQL][DB][DATA_MISSING] Block not found.');
6565
}
6666
return buildBlockOutput(output);
6767
}

0 commit comments

Comments
 (0)