wavetermdev/waveterm · critical
error inserting mainserver: %w
Error message
error inserting mainserver: %w
What it means
InitMainServer loads the singleton MainServer record; if it is not found it creates a new one with a fresh UUID and inserts it. This error wraps a failure of that DBInsert, i.e. a brand-new MainServer record could not be persisted.
Source
Thrown at pkg/wcore/wcore.go:175
if err != nil {
log.Printf("[error] sending no-telemetry update: %v\n", err)
return
}
}()
}
func InitMainServer() error {
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelFn()
mainServer, err := wstore.DBGetSingleton[*waveobj.MainServer](ctx)
if err == wstore.ErrNotFound {
mainServer = &waveobj.MainServer{
OID: uuid.NewString(),
}
err = wstore.DBInsert(ctx, mainServer)
if err != nil {
return fmt.Errorf("error inserting mainserver: %w", err)
}
} else if err != nil {
return fmt.Errorf("error getting mainserver: %w", err)
}
needsUpdate := false
if mainServer.JwtPrivateKey == "" || mainServer.JwtPublicKey == "" {
keyPair, err := wavejwt.GenerateKeyPair()
if err != nil {
return fmt.Errorf("error generating jwt keypair: %w", err)
}
mainServer.JwtPrivateKey = base64.StdEncoding.EncodeToString(keyPair.PrivateKey)
mainServer.JwtPublicKey = base64.StdEncoding.EncodeToString(keyPair.PublicKey)
needsUpdate = true
}
if needsUpdate {
err = wstore.DBUpdate(ctx, mainServer)View on GitHub (pinned to a4447c1563)
Solutions
- Check the wrapped wstore error for the root DB failure
- Ensure the Wave data directory is writable and not locked by another process
- Remove a corrupted DB to allow clean re-initialization
- Retry launch — the second run should find an existing mainserver row
Defensive patterns
Strategy: try-catch
Validate before calling
// mainserver singleton presence check
_, err := wstore.DBGetSingleton[*waveobj.MainServer](ctx)
if err != nil && !errors.Is(err, wstore.ErrNotFound) { log.Printf("DB unhealthy: %v", err) } Try / catch
err := wcore.InitMainServer(ctx)
if err != nil && strings.Contains(err.Error(), "inserting mainserver") {
log.Printf("mainserver init failed: %v", err)
return err
} Prevention
- Ensure the data directory is writable before first launch
- Avoid racing multiple instances to create the singleton
- Verify DB integrity after crashes
- Keep disk space available on the data volume
When it happens
Trigger: wstore.DBGetSingleton returns wstore.ErrNotFound, the new MainServer object is built, and wstore.DBInsert then fails — DB locked, unwritable, or schema problems on first launch.
Common situations: First launch creating the mainserver record on a failing DB; two instances racing to create the singleton simultaneously; corrupted data directory.
Related errors
- error updating client: %w
- error inserting client: %w
- error updating mainserver: %w
- error updating window: %w
- error inserting window: %w
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/4a969790ca82e8a9.
Report an issue: GitHub.