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

  1. Check the wrapped wstore error for the root DB failure
  2. Ensure the Wave data directory is writable and not locked by another process
  3. Remove a corrupted DB to allow clean re-initialization
  4. 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

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


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/4a969790ca82e8a9. Report an issue: GitHub.