{"record":{"id":"d19cb91a3c8c8619","repo":"ruvnet/RuView","slug":"invalid-settings-file-format","errorCode":null,"errorMessage":"Invalid settings file format","messagePattern":"Invalid settings file format","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ui/components/SettingsPanel.js","lineNumber":783,"sourceCode":"  importSettings(event) {\n    const file = event.target.files[0];\n    if (!file) return;\n\n    const reader = new FileReader();\n    reader.onload = (e) => {\n      try {\n        const data = JSON.parse(e.target.result);\n        \n        if (data.settings) {\n          this.settings = { ...this.getDefaultSettings(), ...data.settings };\n          this.updateUI();\n          this.saveSettings();\n          this.notifyCallback('onSettingsChange', { imported: true, settings: this.settings });\n          this.notifyCallback('onImport', data);\n          this.updateStatus('Settings imported successfully');\n          this.logger.info('Settings imported successfully');\n        } else {\n          throw new Error('Invalid settings file format');\n        }\n      } catch (error) {\n        this.updateStatus('Error importing settings');\n        this.logger.error('Error importing settings', { error: error.message });\n        alert('Error importing settings: ' + error.message);\n      }\n    };\n    \n    reader.readAsText(file);\n    event.target.value = ''; // Reset file input\n  }\n\n  saveSettings() {\n    if (this.config.allowConfigPersistence) {\n      try {\n        localStorage.setItem(`pose-settings-${this.containerId}`, JSON.stringify(this.settings));\n      } catch (error) {\n        this.logger.warn('Failed to save settings to localStorage', { error: error.message });","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/ui/components/SettingsPanel.js#L765-L801","documentation":"SettingsPanel's import handler (ui/components/SettingsPanel.js) parses an uploaded file with JSON.parse, then requires a top-level `settings` property ({ ...defaults, ...data.settings }). A file that parses as JSON but lacks `settings` throws 'Invalid settings file format'; the catch block surfaces it via alert. Note that raw JSON syntax errors are caught by the same catch but show their own parse message.","triggerScenarios":"Importing an exported config wrapped differently (e.g. { config: {...} }), a settings dump from another app/version, or a hand-edited file where the `settings` key was renamed or removed.","commonSituations":"Users importing settings exported by an older UI version with a different envelope; importing the wrong JSON file (calibration data, zone config); manual edits that flattened the settings object to the top level.","solutions":["Re-export settings from a working SettingsPanel and import that file — it has the expected { settings: {...} } shape.","Wrap your existing values: edit the JSON so the top level is { \"settings\": { ...your current keys... } }.","Open the file and confirm JSON.parse succeeds and a top-level `settings` object exists before importing."],"exampleFix":"// before — file contents: { \"theme\": \"dark\", \"confidence\": 0.6 }\n// after  — file contents: { \"settings\": { \"theme\": \"dark\", \"confidence\": 0.6 } }","handlingStrategy":"validation","validationCode":"const data = JSON.parse(text);\nif (!data || typeof data !== 'object' || Array.isArray(data) || typeof data.settings !== 'object' || data.settings === null) {\n  throw new Error('Invalid settings file format: expected { \"settings\": { ... } }');\n}\n// safe to hand to SettingsPanel import / merge","typeGuard":"function isSettingsExport(v) {\n  return typeof v === 'object' && v !== null && !Array.isArray(v)\n    && typeof v.settings === 'object' && v.settings !== null;\n}","tryCatchPattern":"try {\n  importSettings(file);\n} catch (error) {\n  // JSON.parse failures and shape failures land here; show the message via non-blocking UI\n  showToast(`Import failed: ${error.message}`);\n}","preventionTips":["Only import files previously exported by the same SettingsPanel version.","Keep exports as { settings: {...} } — never flatten the envelope.","After hand edits, validate the shape with a JSON tool before importing."],"tags":["ui","settings","import","json","file-format"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}