mudler/LocalAI · error · Error

unknown error

Error message

unknown error

What it means

Thrown by toggleDefault() in the PII default-detectors card when settingsApi.save({pii_default_detectors: next}) resolves with body.success === false and body.error is empty/undefined. The 'unknown error' string is the fallback placeholder, meaning the settings API rejected the write but returned no error message. The busy-row Set is always cleared in finally, so the toggle re-enables after failure.

Source

Thrown at core/http/react-ui/src/pages/Middleware.jsx:320

// shows every available detector, so admins toggle defaults instead of retyping
// names, and link straight to each detector's config to edit its policy.
function DetectorModels({ pii, addToast, onChanged }) {
  const navigate = useNavigate()
  const location = useLocation()
  const rows = useMemo(() => pii.detector_models || [], [pii.detector_models])
  // Names currently in the default set; the toggle adds/removes against this.
  const defaults = useMemo(() => pii.default_detectors || [], [pii.default_detectors])
  // Track which rows are mid-save to disable just that toggle (optimistic).
  const [busy, setBusy] = useState(() => new Set())

  const toggleDefault = async (name, on) => {
    const next = on
      ? [...new Set([...defaults, name])]
      : defaults.filter(d => d !== name)
    setBusy(prev => new Set(prev).add(name))
    try {
      const body = await settingsApi.save({ pii_default_detectors: next })
      if (body && body.success === false) throw new Error(body.error || 'unknown error')
      addToast?.(on ? `${name} added to default detectors` : `${name} removed from default detectors`, 'success')
      onChanged?.()
    } catch (err) {
      addToast?.(`Failed to save: ${err.message}`, 'error')
    } finally {
      setBusy(prev => { const n = new Set(prev); n.delete(name); return n })
    }
  }

  return (
    <div className="card pad-md mb-md">
      <div className="hstack hstack--between mb-sm">
        <span className="text-base fw-semibold">Detector models</span>
        <button
          className="btn btn-secondary btn-sm"
          onClick={() => navigate('/app/model-editor?template=secret-filter', { state: fromState(location, 'Middleware') })}
          title="Add a NER or pattern detector model"
        >

View on GitHub (pinned to 44413a9d06)

Solutions

  1. Open browser devtools network tab, find the settings save request, and inspect the raw response body
  2. Check the config file LocalAI writes is writable (docker inspect mount modes; ls -l on the config path)
  3. Verify the server version supports pii_default_detectors (compare with the settings registry in the running binary)
  4. Retry the toggle after fixing writability; onChanged?.() is not called on failure so the UI stays consistent

Example fix

// before
if (body && body.success === false) throw new Error(body.error || 'unknown error')

// after: surface the HTTP status too when the API omits the message
if (body && body.success === false) {
  throw new Error(body.error || `settings save rejected (HTTP ${body.status ?? 'no status'}, no error message)`)
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate the next detector list before saving: known names, no dupes, serializable
function validDetectorList(next) {
  return Array.isArray(next) && next.length > 0 && next.every(n => typeof n === 'string' && /^[\w.-]+$/.test(n)) && new Set(next).size === next.length
}

Type guard

function isSettingsReject(body) {
  return !!body && typeof body === 'object' && body.success === false
}

Try / catch

try {
  const body = await settingsApi.save({ pii_default_detectors: next })
  if (isSettingsReject(body)) throw new Error(body.error || 'server rejected pii_default_detectors without a reason')
} catch (err) {
  addToast?.(`Detector toggle failed: ${err.message}`, 'error')
  // finally-block already restores the toggle; nothing else to roll back
}

Prevention

When it happens

Trigger: POST/PUT to the settings endpoint returns {success:false} with no error field — e.g. config file not writable, settings registry rejecting the pii_default_detectors key, or a validation failure server-side that omits the message.

Common situations: LocalAI config.yaml mounted read-only (Docker volume ro); a version mismatch where the running server does not know the pii_default_detectors key; settings backend returning success:false from a mutex/lock failure during concurrent saves.

Related errors


AI-assisted analysis of mudler/LocalAI@44413a9d06 (2026-08-15). Data as JSON: /api/errors/e58537c580eedc41. Report an issue: GitHub.