wavetermdev/waveterm · error

ijson budget must be non-negative

Error message

ijson budget must be non-negative

What it means

A negative IJsonBudget is meaningless (a budget cannot be less than zero), so MakeFile rejects it during option validation. Note the ordering: the 'requires ijson' check runs first, so this error only appears when IJson is true (or the budget is negative and IJson is true).

Source

Thrown at pkg/filestore/blockstore.go:134

	if opts.MaxSize < 0 {
		return fmt.Errorf("max size must be non-negative")
	}
	if opts.Circular && opts.MaxSize <= 0 {
		return fmt.Errorf("circular file must have a max size")
	}
	if opts.Circular && opts.IJson {
		return fmt.Errorf("circular file cannot be ijson")
	}
	if opts.Circular {
		if opts.MaxSize%partDataSize != 0 {
			opts.MaxSize = (opts.MaxSize/partDataSize + 1) * partDataSize
		}
	}
	if opts.IJsonBudget > 0 && !opts.IJson {
		return fmt.Errorf("ijson budget requires ijson")
	}
	if opts.IJsonBudget < 0 {
		return fmt.Errorf("ijson budget must be non-negative")
	}
	return withLock(s, zoneId, name, func(entry *CacheEntry) error {
		if entry.File != nil {
			return fs.ErrExist
		}
		now := time.Now().UnixMilli()
		file := &WaveFile{
			ZoneId:    zoneId,
			Name:      name,
			Size:      0,
			CreatedTs: now,
			ModTs:     now,
			Opts:      opts,
			Meta:      meta,
		}
		return dbInsertFile(ctx, file)
	})
}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Pass IJsonBudget >= 0; use 0 for 'no explicit budget' semantics.
  2. Normalize sentinels before the call: if budget < 0 { budget = 0 }.
  3. Clamp computed budgets: opts.IJsonBudget = max(0, computed).

Example fix

// before
opts := wshrpc.FileOpts{IJson: true, IJsonBudget: -1} // meant 'unlimited'
// after
budget := -1
if budget < 0 {
	budget = 0
}
opts := wshrpc.FileOpts{IJson: true, IJsonBudget: budget}
Defensive patterns

Strategy: validation

Validate before calling

func validBudget(opts wshrpc.FileOpts) bool { return opts.IJsonBudget >= 0 }
if !validBudget(opts) {
	return fmt.Errorf("ijsonBudget must be >= 0")
}

Try / catch

if err := store.MakeFile(ctx, zoneId, name, meta, opts); err != nil {
	if strings.Contains(err.Error(), "ijson budget must be non-negative") {
		opts.IJsonBudget = 0
		err = store.MakeFile(ctx, zoneId, name, meta, opts)
	}
	if err != nil {
		return err
	}
}

Prevention

When it happens

Trigger: Calling MakeFile with opts.IJsonBudget < 0 — e.g. a caller using -1 as an 'unlimited' sentinel or a size computation underflowing.

Common situations: Using -1 to mean 'no budget limit' (not supported; use 0); arithmetic like totalBudget - used going negative before the call; unvalidated user input parsed into the budget field.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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