kataras/iris · error

nil loader

Error message

nil loader

What it means

I18n.reload (invoked by Reset) requires a loader function that knows how to load translation files. If the I18n instance was created without a loader (nil), reloading cannot proceed and this plain error is returned.

Source

Thrown at i18n/i18n.go:190

	i.loader = loader
	i.matcher = &Matcher{
		strict:             len(tags) > 0,
		Languages:          tags,
		matcher:            language.NewMatcher(tags),
		defaultMessageFunc: i.DefaultMessageFunc,
	}

	return i.reload()
}

// reload loads the language files from the provided Loader,
// the `New` package-level function preloads those files already.
func (i *I18n) reload() error { // May be an exported function, if requested.
	i.mu.Lock()
	defer i.mu.Unlock()

	if i.loader == nil {
		return fmt.Errorf("nil loader")
	}

	localizer, err := i.loader(i.matcher)
	if err != nil {
		return err
	}

	i.localizer = localizer
	return nil
}

// Loaded reports whether `New` or `Load/LoadAssets` called.
func (i *I18n) Loaded() bool {
	return i != nil && i.loader != nil && i.localizer != nil && i.matcher != nil
}

// Tags returns the registered languages or dynamically resolved by files.
// Use `Load` or `LoadAssets` first.

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Pass a valid loader to i18n.New (e.g. i18n.Glob, i18n.Dbi or a custom Loader) before calling Reset
  2. Ensure initialization completes before any file-watcher or signal handler triggers reload
  3. Guard reload paths: only call Reset when the loader was configured
  4. If loader is intentionally optional, check i.loader == nil before invoking reload

Example fix

// before
i, _ := i18n.New(nil, "en")
i.Reset()
// after
i, _ := i18n.New(i18n.Glob("./locales/*.json"), "en")
i.Reset()
Defensive patterns

Strategy: type-guard

Validate before calling

if i.Loader == nil || reflect.ValueOf(i.Loader).IsNil() {
    return errors.New("i18n: cannot reset without a loader")
}

Type guard

func (i *I18n) hasLoader() bool { return i.loader != nil }

Try / catch

if err := i.Reset(); err != nil {
    if err.Error() == "nil loader" {
        log.Fatal("i18n initialized without a loader; cannot reload")
    }
    return err
}

Prevention

When it happens

Trigger: Calling i18n.Reset() (or any path that triggers reload) on an I18n instance built without i18n.New(loader...) supplying a loader — e.g. a zero-value I18n or one constructed in tests without wiring a loader.

Common situations: Hot-reloading translations on SIGHUP or file change when the app was initialized partially; refactoring away the loader but leaving Reset calls in place; test fixtures constructing &i18n.I18n{} directly.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/62d5febda608bdb3. Report an issue: GitHub.