🚧 VeloxKit is pre-release software. APIs may change before v1.0. Get started →
Documentation
APIs & Bindings
crash

crash Stable WINMACLNX

Automatic crash capture for both Rust panics and unhandled JavaScript errors. Reports are persisted to disk and survive the process — read them on next launch to surface diagnostics to the user.

Capability

veloxkit.config.json
{
  "capabilities": ["crash"]
}

Import

import { crash } from 'veloxkit'

How it works

VeloxKit installs handlers automatically when the crash capability is enabled:

EventStorage
Rust panic~/.velox/crashes/rust_{timestamp}.json
globalThis.onerror~/.velox/crashes/js_{timestamp}.json
globalThis.onunhandledrejectionSame path

No code changes required — enabling the capability is sufficient.


crash.getReports()

Read all crash reports from previous sessions.

const reports = await crash.getReports()
// [{ file: 'js_1717600000000.json', content: '{"type":"js_error",...}' }]

Returns Promise<Array<{ file: string, content: string }>>

Report content shapes:

// Rust panic
{
  type:      'rust_panic',
  message:   'index out of bounds: the len is 3 but the index is 5',
  thread:    'main',
  timestamp: 1717600000000
}
 
// JS error
{
  type:      'js_error',
  timestamp: 1717600000000,
  message:   'Cannot read properties of undefined',
  source:    'app.js',
  line:      42,
  stack:     '...'
}
 
// Unhandled Promise rejection
{
  type:      'unhandled_rejection',
  timestamp: 1717600000000,
  message:   'Network request failed',
  stack:     '...'
}

crash.clearReports()

Delete all stored crash reports from disk.

crash.clearReports()

crash.setEndpoint(url)

Store a URL that your code uses to upload crash reports (VeloxKit does not upload automatically).

crash.setEndpoint('https://crashes.example.com/ingest')
// crash._endpoint is now set; use it in your upload logic

Pattern: crash dialog on next launch

import { crash } from 'veloxkit'
import { useEffect, useState } from 'react'
 
function App() {
  const [priorCrash, setPriorCrash] = useState(null)
 
  useEffect(() => {
    crash.getReports().then(reports => {
      if (reports.length > 0) {
        setPriorCrash(reports[0])
        crash.clearReports()
      }
    })
  }, [])
 
  if (priorCrash) {
    const info = JSON.parse(priorCrash.content)
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', padding: 24 }}>
        <Text style={{ fontSize: 20, fontWeight: '700', marginBottom: 12 }}>
          The app crashed last session
        </Text>
        <Text style={{ color: '#9999bb', fontSize: 14, marginBottom: 24 }}>
          {info.message}
        </Text>
        <Pressable
          onPress={() => setPriorCrash(null)}
          style={{ padding: 12, backgroundColor: '#7aa2f7', borderRadius: 8 }}
        >
          <Text style={{ color: '#171923', fontWeight: '600' }}>Continue</Text>
        </Pressable>
      </View>
    )
  }
 
  return <MainApp />
}

Pattern: upload reports on startup

useEffect(() => {
  async function checkCrashes() {
    const reports = await crash.getReports()
    if (reports.length === 0) return
 
    for (const report of reports) {
      await fetch('https://crashes.example.com/ingest', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: report.content,
      }).catch(() => {})  // best-effort; never block startup
    }
 
    crash.clearReports()
  }
 
  checkCrashes()
}, [])

Reports are stored in ~/.velox/crashes/ (or %USERPROFILE%\.velox\crashes\ on Windows). The directory is created automatically.