jlcodes99/cockpit-tools · error
Invalid format
Error message
Invalid format
What it means
Guard in MfaVaultManager's import handler: the chosen file was read and JSON.parse succeeded, but the parsed root is not an array. The MFA vault import expects a JSON array of record objects, so any other shape (single object, wrapper with metadata) is rejected as 'Invalid format' before merging into the vault.
Source
Thrown at src/components/MfaVaultManager.tsx:392
resolve();
return;
}
const reader = new FileReader();
reader.onload = (res) => {
dataStr = res.target?.result as string;
resolve();
};
reader.onerror = reject;
reader.readAsText(file);
};
input.click();
});
}
if (!dataStr) return;
const parsed = JSON.parse(dataStr);
if (!Array.isArray(parsed)) throw new Error('Invalid format');
setRecords(prev => {
const incoming = parsed
.map(normalizeMfaRecord)
.filter((item): item is MfaRecord => !!item);
return dedupeMfaRecordsBySecret([...incoming, ...prev]);
});
} catch (err) {
console.error('Import error:', err);
alert(t('mfaVault.importErrorMsg', '导入失败,请检查文件内容格式。'));
}
};
const handlePasteImage = async (event: ClipboardEvent<HTMLInputElement>) => {
const items = Array.from(event.clipboardData?.items || []);
const imageItem = items.find(item => item.type.startsWith('image/'));
if (!imageItem) return;
View on GitHub (pinned to 1ed8b77992)
Solutions
- Re-export the MFA records and ensure the export root is a JSON array
- If importing a single record, wrap it in an array
- Check that the file was not produced by a different tool with a wrapper schema
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/components/MfaVaultManager.tsx:392 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/27e85432f2665139.
Report an issue: GitHub.