Errors

A call can fail because a definition is missing, a document is invalid, or the database refuses a change. The examples use the people data to show these results. Use the status and diagnostic fields to identify the failure.

Binding errors

LanguageFailure
CReturns a status. The owner that its operation names holds the diagnostic.
GoReturns *Error.
RustReturns Result<_, Error>.
ClojureThrows clojure.lang.ExceptionInfo with diagnostic data.
PythonRaises StardustError.
OdinReturns an Error beside its result.

The error record gives the fields in your language. Statuses gives the failure conditions of each operation.

error

This record describes a failure with its status and diagnostic. The binding copies the diagnostic before it releases the native owner.

FieldTypeUnitAbsent
codestringNone—
messagestringNone—
path*stringNonenil
field*stringNonenil
entity*int64Nonenil
offset*int64Bytesnil
statusStatusNone—

Statuses

Each status names a class of failure. The table lists codes from the binding. Native diagnostic codes can differ.

StatusInvalidArgument

Codes: time_out_of_range, invalid_argument, out_of_range, unsigned_value, non_finite_number, cycle, unsupported_type, too_large, native_failure, live_children.

WhenOperations
the text is malformed, the format is unknown or a number is outside i64 or finite f64Parse
the format is unknown or the width is negativeDocument.Serialize
the text is malformed, a format is unknown or the width is negativeConvert
the value has a host type with no document form, a number outside i64 or finite f64, or a cycleFromValue
the node breaks the preorder rules or has an invalid kind or numberBuilder.Add
a node breaks the preorder rules or has an invalid kind or numberBuilder.AddMany
the builder has no root or a container is still openBuilder.Seal
id is not a node of the documentDocument.Read, Document.Children
start is past the last node or capacity is negativeDocument.ReadMany
id is not an object node of the documentDocument.Member, Document.Members
the node is not an integer numberDocument.I64
the node is not a number or its value overflows f64Document.F64
the arguments include an undeclared macro parameterBuildMacro, ExpandMacro
the file is not a database or an option is invalidOpen
the parameters or run options are invalidQuery.Run, Mutation.Run
the parameters or subscription options are invalidQuery.Subscribe
max_wait is negativeSubscription.Next, Database.ReactorsSync
the patch is not an entity-keyed objectDatabase.MergePatch
the kind or the pattern is invalidDatabase.Definitions

StatusInvalidJSON

WhenOperations
JSON text is malformedParse, Convert

StatusCompileFailed

WhenOperations
the expression does not compileBuild
the expansion does not compileBuildMacro

StatusEvaluationFailed

WhenOperations
the expression fails on the inputProgram.Evaluate
the query fails or exceeds max_costQuery.Run
the page does not renderRows.Next
a page does not renderRows.Pages, Rows.AllPages
a rerun of the query failed. Every later call reports this failureSubscription.Next
a rerun of the query failedSubscription.All
the mutation failsMutation.Run

StatusOutOfMemory

Codes: out_of_memory.

StatusNotFound

Codes: not_found.

WhenOperations
the object has no member with the keyDocument.Member
the macro refers to an unknown macroBuildMacro, ExpandMacro
the parent directory is missing, or the file is missing and create is falseOpen
no definition is stored at the pathDatabase.Query, Database.Mutation, Database.Definition
the stored query definition was deletedQuery.Run

StatusLocked

WhenOperations
another process holds the lock after lock_timeoutOpen

StatusConflict

WhenOperations
concurrent writes prevent the commitMutation.Run

StatusInvalidDefinition

WhenOperations
the macro is invalid or expands recursivelyBuildMacro, ExpandMacro
the definition is invalidDatabase.Query, Database.Mutation
the loaded query definition is invalidQuery.Run
the query or its callable definitions are invalidQuery.Subscribe
the mutation selection or definition is invalidMutation.Run
the patched definition is invalidDatabase.PatchDefinition

StatusSchemaViolation

WhenOperations
the write breaks a schemaMutation.Run

StatusInvalidCommitTime

WhenOperations
the #_tx commit time is not later than the last commitDatabase.MergePatch

StatusClosed

Codes: closed.

StatusRejected

WhenOperations
a mutation target or write guard refuses the writeMutation.Run
the database refuses the patchDatabase.MergePatch

StatusUnsupported

Codes: abi_version.

WhenOperations
found differs from the ABI version of the bindingCheckVersion

StatusCancelled

Codes: cancelled.

WhenOperations
the subscription is cancelled or closedSubscription.Next

StatusTimeout

WhenOperations
max_wait passed firstDatabase.ReactorsSync

StatusUnavailable

WhenOperations
the database does not enable the reactors pluginDatabase.ReactorsStatus, Database.ReactorsSync

StatusFailed

WhenOperations
a live mutation failure stands. reactors_status describes itDatabase.ReactorsSync

Refusal examples

The generator captured each result from the native library.

convert

duplicateText holds this document:

dust14B
'{:a 1 :a 2}'
go339B
source, err := stardust.Parse(duplicateText, stardust.DUST)
if err != nil {
	return err
}
defer source.Close()

root, err := source.Root()
if err != nil {
	return err
}
view, err := source.Read(root)
if err != nil {
	return err
}

failed, result := stardust.Parse([]byte(view.Text), stardust.EDN)
if failed != nil {
	defer failed.Close()
}
Result / 149B
{code    invalid_edn
 message invalid EDN (Duplicate_Key) at offset 6
 path    null
 field   null
 entity  null
 offset  6
 status  invalid_argument}

Refuse a metadata-only transaction

patchText holds this document:

dust16B
#_tx {author x}
go144B
patch, err := stardust.Parse(patchText, stardust.DUST)
if err != nil {
	return err
}
defer patch.Close()

_, result := db.MergePatch(patch, nil)
Result / 203B
{code    invalid
 message the write is invalid: check entity ids, field names, values and #_tx (a patch of only #_tx is refused)
 path    null
 field   null
 entity  null
 offset  null
 status  rejected}

Refuse a repeated commit time

futureText holds this document:

dust67B
#_d  {x 1}
#_tx {stardust/committedAt {#utc 2200-01-01T00:00:00Z}}

patchText holds this document:

dust67B
#_e  {x 2}
#_tx {stardust/committedAt {#utc 2200-01-01T00:00:00Z}}
go322B
future, err := stardust.Parse(futureText, stardust.DUST)
if err != nil {
	return err
}
defer future.Close()

if _, err := db.MergePatch(future, nil); err != nil {
	return err
}

patch, err := stardust.Parse(patchText, stardust.DUST)
if err != nil {
	return err
}
defer patch.Close()

_, result := db.MergePatch(patch, nil)
Result / 195B
{code    invalid_commit_time
 message stardust/committedAt must be strictly newer than the latest commit time
 path    null
 field   null
 entity  null
 offset  null
 status  invalid_commit_time}

Refuse an invalid query definition

queryText holds this document:

dust10B
find [?x]
go194B
definition, err := stardust.Parse(queryText, stardust.DUST)
if err != nil {
	return err
}
defer definition.Close()

query, result := db.Query(definition)
if query != nil {
	defer query.Close()
}
Result / 136B
{code    unbound_variable
 message Unbound_Variable
 path    null
 field   null
 entity  null
 offset  null
 status  invalid_definition}

Report a missing stored query

go88B
query, result := db.QueryPath("people/missing")
if query != nil {
	defer query.Close()
}
Result / 140B
{code    not_found
 message no definition at this path
 path    people/missing
 field   null
 entity  null
 offset  null
 status  not_found}

Report a malformed byte at offset zero

malformedText holds these bytes:

text1B
]
go105B
failed, result := stardust.Parse(malformedText, stardust.DUST)
if failed != nil {
	defer failed.Close()
}
Result / 137B
{code    invalid_dust
 message Invalid_Syntax at offset 0
 path    null
 field   null
 entity  null
 offset  0
 status  invalid_argument}

Report malformed DUST

malformedText holds these bytes:

text1B
[
go174B
failed, err := stardust.Parse(malformedText, stardust.DUST)
if failed != nil {
	defer failed.Close()
}

var result *stardust.Error
if !errors.As(err, &result) {
	return err
}
Result / 137B
{code    invalid_dust
 message Unexpected_End at offset 2
 path    null
 field   null
 entity  null
 offset  2
 status  invalid_argument}