Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Throw errors on specific graphql error messages #638

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/indexer-service/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,41 @@ export class QueryProcessor implements QueryProcessorInterface {
this.receiptManager = receiptManager
}

validateResponse(query: String, response: AxiosResponse, ipfsHash: String): void {
// Check response for specific graphql errors
const throwableErrors = [
'Failed to decode `block.hash` value:',
'Store error: database unavailable',
'Store error: store error: Fulltext search is not yet deterministic',
'Failed to decode `block.number` value:'
]

// Optimization: Parse only if the message is small enough, presume there are no critical errors otherwise
if (response.data.length > 500) {
return
}

const responseData = JSON.parse(response.data);
if (responseData.errors) {
this.logger.debug('GraphQL errors', {
deployment: ipfsHash,
errors: responseData.errors,
query,
})
for (const graphqlError of responseData.errors) {
const isThrowableError = throwableErrors.some((errorString) =>
graphqlError.message.startsWith(errorString)
);
if (isThrowableError) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const error = Error(graphqlError.message) as any
error.status = 500;
throw error;
}
}
}
}

async executeFreeQuery(query: FreeQuery): Promise<Response<UnattestedQueryResult>> {
const { subgraphDeploymentID } = query

Expand All @@ -104,6 +139,8 @@ export class QueryProcessor implements QueryProcessorInterface {
query.query,
)

this.validateResponse(query.query, response, subgraphDeploymentID.ipfsHash)

return {
status: 200,
result: {
Expand Down Expand Up @@ -145,6 +182,8 @@ export class QueryProcessor implements QueryProcessorInterface {
throw error
}

this.validateResponse(query, response, subgraphDeploymentID.ipfsHash)

let attestation = null
if (response.headers['graph-attestable'] == 'true') {
attestation = await signer.createAttestation(query, response.data)
Expand Down