Skip to content

Commit

Permalink
Merge pull request #2273 from headlamp-k8s/improve-error-message
Browse files Browse the repository at this point in the history
frontend: KubeConfigLoader: Improve error message
  • Loading branch information
joaquimrocha authored Aug 30, 2024
2 parents 9f1bc4c + c9bd2c5 commit 8bcb5b5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
13 changes: 10 additions & 3 deletions frontend/src/components/cluster/KubeConfigLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,19 @@ function KubeConfigLoader() {
...new Uint8Array(reader.result as ArrayBuffer),
]);
const doc = yaml.load(data) as kubeconfig;
if (!doc.clusters || !doc.contexts) {
throw new Error('Invalid kubeconfig file');
if (!doc.clusters) {
throw new Error(t('translation|No clusters found!'));
}
if (!doc.contexts) {
throw new Error(t('translation|No contexts found!'));
}
setFileContent(doc);
} catch (err) {
setError(t('translation|Load a valid kubeconfig'));
setError(
t(`translation|Invalid kubeconfig file: {{ errorMessage }}`, {
errorMessage: (err as Error).message,
})
);
return;
}
};
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/i18n/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
"Add Cluster": "Cluster hinzufügen",
"Error setting up clusters, please load a valid kubeconfig file": "Fehler beim Einrichten der Cluster. Bitte laden Sie eine korrekte kubeconfig-Datei",
"Couldn't read kubeconfig file": "Konnte die kubeconfig-Datei nicht lesen",
"Load a valid kubeconfig": "Laden einer korrekten kubeconfig",
"No clusters found!": "",
"No contexts found!": "",
"Invalid kubeconfig file: {{ errorMessage }}": "",
"Drag & drop or choose kubeconfig file here": "Ziehen Sie die Datei per Drag & Drop oder wählen Sie kubeconfig hier aus",
"Choose file": "Datei auswählen",
"Select clusters": "Cluster auswählen",
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
"Add Cluster": "Add Cluster",
"Error setting up clusters, please load a valid kubeconfig file": "Error setting up clusters, please load a valid kubeconfig file",
"Couldn't read kubeconfig file": "Couldn't read kubeconfig file",
"Load a valid kubeconfig": "Load a valid kubeconfig",
"No clusters found!": "No clusters found!",
"No contexts found!": "No contexts found!",
"Invalid kubeconfig file: {{ errorMessage }}": "Invalid kubeconfig file: {{ errorMessage }}",
"Drag & drop or choose kubeconfig file here": "Drag & drop or choose kubeconfig file here",
"Choose file": "Choose file",
"Select clusters": "Select clusters",
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/i18n/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
"Add Cluster": "Añadir cluster",
"Error setting up clusters, please load a valid kubeconfig file": "Error al configurar los clusters, por favor cargue un archivo kubeconfig válido",
"Couldn't read kubeconfig file": "No se pudo leer el archivo kubeconfig",
"Load a valid kubeconfig": "Cargar un kubeconfig válido",
"No clusters found!": "",
"No contexts found!": "",
"Invalid kubeconfig file: {{ errorMessage }}": "",
"Drag & drop or choose kubeconfig file here": "Arrastre y suelte o elija el archivo kubeconfig aquí",
"Choose file": "Elija el archivo",
"Select clusters": "Seleccione los clusters",
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/i18n/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
"Add Cluster": "Ajouter un cluster",
"Error setting up clusters, please load a valid kubeconfig file": "Erreur lors de la configuration des clusters, veuillez charger un fichier kubeconfig valide",
"Couldn't read kubeconfig file": "Impossible de lire le fichier kubeconfig",
"Load a valid kubeconfig": "Charger un kubeconfig valide",
"No clusters found!": "",
"No contexts found!": "",
"Invalid kubeconfig file: {{ errorMessage }}": "",
"Drag & drop or choose kubeconfig file here": "Glisser-déposer ou choisir le fichier kubeconfig ici",
"Choose file": "Choisir un fichier",
"Select clusters": "Sélectionner des clusters",
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/i18n/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
"Add Cluster": "Adicionar Cluster",
"Error setting up clusters, please load a valid kubeconfig file": "Erro ao configurar clusters, por favor carregue um ficheiro kubeconfig válido",
"Couldn't read kubeconfig file": "Não foi possível ler o ficheiro kubeconfig",
"Load a valid kubeconfig": "Carregue um kubeconfig válido",
"No clusters found!": "",
"No contexts found!": "",
"Invalid kubeconfig file: {{ errorMessage }}": "",
"Drag & drop or choose kubeconfig file here": "Arraste e largue ou escolha o ficheiro kubeconfig aqui",
"Choose file": "Escolha o ficheiro",
"Select clusters": "Selecione os clusters",
Expand Down

0 comments on commit 8bcb5b5

Please sign in to comment.