AdguardTeam/AdGuardHome · error

adding %q: %w

Error message

adding %q: %w

What it means

dayRange.validate rejects a nonzero range whose end is negative: 'end <val> is negative'. A negative end cannot represent a valid time-of-day interval and fails schedule parsing immediately.

Source

Thrown at internal/aghos/fswatcher.go:149

	// See https://pkg.go.dev/github.com/fsnotify/fsnotify@v1.7.0#readme-watching-a-file-doesn-t-work-well.
	dirName := name
	if !fi.IsDir() {
		dirName = filepath.Dir(name)
	}

	w.filesMu.Lock()
	defer w.filesMu.Unlock()

	names := w.files[dirName]
	if names == nil {
		names = container.NewMapSet[string]()
		w.files[dirName] = names
	}
	names.Add(name)

	err = w.watcher.Add(dirName)
	if err != nil {
		return fmt.Errorf("adding %q: %w", dirName, err)
	}

	return nil
}

// Remove implements the [FSWatcher] interface for *OSWatcher.  It's safe for
// concurrent use.
func (w *OSWatcher) Remove(name string) (err error) {
	defer func() { err = errors.Annotate(err, "%s: %w", osWatcherPref) }()

	dirName := filepath.Dir(name)

	w.filesMu.Lock()
	defer w.filesMu.Unlock()

	names, ok := w.files[name]
	if ok {
		dirName = name

View on GitHub (pinned to b41aefbe51)

Solutions

  1. Set end to a positive minute-aligned time within the day
  2. Fix the generation logic to clamp or use absolute times
  3. Disable the day by omitting it instead of using negatives
  4. Add schedule validation to your config pipeline

Example fix

// before
{"start": "01:00", "end": "-02:00"}
// after
{"start": "01:00", "end": "02:00"}
Defensive patterns

Strategy: validation

Validate before calling

if end < 0 { end = 0 }

Type guard

func isNonNegative(d time.Duration) bool { return d >= 0 }

Try / catch

if err := unmarshalSchedule(data); err != nil && strings.Contains(err.Error(), "is negative") {
    // fix end value, retry
}

Prevention

When it happens

Trigger: A weekly schedule day with a negative end value (e.g. "-02:00" or negative duration) in JSON or YAML.

Common situations: Same as negative starts: timezone math, manual edits, or scripts emitting signed durations without clamping.

Understand the failure class

Background: Config validation failed: what "invalid value for {key}" and settings-rejection errors mean across 19 open-source libraries — this error's family across 19 libraries.

Related errors


AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27). Data as JSON: /api/errors/20375a4eed675afe. Report an issue: GitHub.