Error Handling

The SDK provides structured errors with codes, categories, and recovery hints.

ArcflowError#

All errors from the engine are wrapped in ArcflowError:

import { ArcflowError } from '@ozinc/arcflow'
 
try {
  db.query("INVALID QUERY")
} catch (err) {
  if (err instanceof ArcflowError) {
    console.log(err.code)        // "EXPECTED_KEYWORD"
    console.log(err.category)    // "parse"
    console.log(err.message)     // "Expected MATCH, CREATE, MERGE, ..."
    console.log(err.suggestion)  // "Expected MATCH or CREATE" (when available)
  }
}

Error categories#

CategoryWhenExample Codes
parseQuery syntax is invalidEXPECTED_KEYWORD, UNEXPECTED_TOKEN, PARSE_ERROR
validationQuery is syntactically valid but semantically wrongUNKNOWN_PROCEDURE, TYPE_MISMATCH, INVALID_ARGUMENT
executionRuntime error during query executionUNKNOWN, general execution failures
integrationInfrastructure or lifecycle errorLOCK_POISONED, HANDLE_BUSY_CONCURRENT_WRITER

Error code reference#

CodeCategoryMeaningFix
EXPECTED_KEYWORDparseQuery syntax wrongCheck MATCH/CREATE/MERGE syntax
UNEXPECTED_TOKENparseUnexpected token in queryRun CALL db.help()
PARSE_ERRORparseGeneral parser failureVerify the GQL/Cypher form against docs/worldcypher
UNKNOWN_PROCEDUREvalidationProcedure doesn't existRun CALL db.procedures()
INVALID_ARGUMENTvalidationProcedure called with wrong-shape argCheck the procedure's recovery_suggestion
WORKFLOW_NOT_FOUNDvalidationWorkflow name doesn't existRun CALL arcflow.workflow.list
STEP_NOT_FOUNDvalidationStep name not in workflowCheck step name spelling
EXECUTION_CONTEXT_MISMATCHintegrationContext guard failedCALL db.setExecutionContext(...) first
UNKNOWN_EXECUTION_CONTEXTvalidationInvalid context stringUse local_cpu, local_gpu, or distributed
TEMPORAL_WAL_NOT_WIREDintegrationAS OF seq used without WAL contextOpen the store with WAL enabled (open() or openInMemory() with sync options)
LOCK_POISONEDintegrationInternal mutex poisonedRestart the process
HANDLE_BUSY_CONCURRENT_WRITERintegrationAnother writer holds the handleRetry after the writer commits, or use a session-bound handle

Common errors and fixes#

Parse errors#

// Wrong:
db.query("FIND (n:Person)")  // EXPECTED_KEYWORD — "FIND" is not a keyword
 
// Right:
db.query("MATCH (n:Person) RETURN n")

Missing RETURN clause#

// Wrong:
db.query("MATCH (n:Person)")  // Needs a RETURN
 
// Right:
db.query("MATCH (n:Person) RETURN n.name")

Using closed database#

db.close()
db.query("RETURN 1")  // throws — the handle is invalid after close()

Programmatic error handling#

try {
  db.query(userProvidedQuery)
} catch (err) {
  if (err instanceof ArcflowError) {
    switch (err.category) {
      case 'parse':
        return { error: 'Invalid query syntax', detail: err.message }
      case 'validation':
        return { error: 'Query validation failed', detail: err.message }
      case 'execution':
        return { error: 'Query execution failed', detail: err.message }
      case 'integration':
        return { error: 'Database error', detail: err.message }
    }
  }
  throw err  // Re-throw unexpected errors
}

Health check#

Use isHealthy() to check if the database is operational:

if (!db.isHealthy()) {
  // Reinitialize or alert
}

See Also#

Try it
Open ↗
Loading engine…