fix: sanitize dataset script errors and persist training start error

This commit is contained in:
imagineer99 2026-03-03 20:15:23 +00:00
commit a0f4566173
4 changed files with 63 additions and 6 deletions

View file

@ -106,7 +106,7 @@ export function HfDatasetSubsetSplitSelectors({
: "rounded-lg border border-amber-200 bg-amber-50 px-3.5 py-2.5 text-xs text-amber-700 dark:border-amber-800 dark:bg-amber-950 dark:text-amber-400"
}
>
Could not fetch dataset splits: {error}
{error}
</div>
)}

View file

@ -16,6 +16,19 @@ const ROLE_REMAP: Record<string, Record<string, string>> = {
sharegpt: { user: "human", assistant: "gpt", system: "system" },
};
function normalizeTrainingStartError(message: string): string {
const normalized = message.toLowerCase();
const isLegacyDatasetScriptError =
normalized.includes("failed to check dataset format") &&
normalized.includes("dataset scripts are no longer supported");
if (isLegacyDatasetScriptError) {
return "This Hub dataset relies on a legacy custom script and isnt supported in this training flow.";
}
return message;
}
export function useTrainingActions() {
const isStarting = useTrainingRuntimeStore((state) => state.isStarting);
const startError = useTrainingRuntimeStore((state) => state.startError);
@ -79,7 +92,9 @@ export function useTrainingActions() {
const response = await startTraining(payload);
if (response.status === "error") {
runtimeStore.setStartError(response.error || response.message);
const rawMessage = response.error || response.message;
const safeMessage = normalizeTrainingStartError(rawMessage);
runtimeStore.setStartError(safeMessage);
runtimeStore.setStarting(false);
return false;
}
@ -88,9 +103,10 @@ export function useTrainingActions() {
await syncTrainingRuntimeFromBackend();
return true;
} catch (error) {
const message =
const rawMessage =
error instanceof Error ? error.message : "Failed to start training";
runtimeStore.setStartError(message);
const safeMessage = normalizeTrainingStartError(rawMessage);
runtimeStore.setStartError(safeMessage);
runtimeStore.setStarting(false);
return false;
}

View file

@ -187,7 +187,6 @@ export const useTrainingRuntimeStore = create<TrainingRuntimeStore>()((set) => (
evalEnabled: payload.eval_enabled ?? state.evalEnabled,
message: payload.message,
error: payload.error,
startError: null,
currentStep:
typeof detailStep === "number" ? Math.max(detailStep, 0) : state.currentStep,
totalSteps:

View file

@ -35,6 +35,37 @@ export interface HfDatasetSplitsResult {
const HF_SPLITS_API = "https://datasets-server.huggingface.co/splits";
function normalizeDatasetSplitsError(message: string): string {
const normalized = message.toLowerCase();
// datasets-server returns technical script/runtime details for legacy datasets.
if (
normalized.includes("dataset scripts are no longer supported") ||
normalized.includes("runs arbitrary python code") ||
normalized.includes(".py")
) {
return "We cant load subset/split options for this Hub dataset because it relies on a legacy custom script.";
}
if (
normalized.includes("unauthorized") ||
normalized.includes("forbidden") ||
normalized.includes("access token") ||
normalized.includes("private") ||
normalized.includes("gated") ||
normalized.includes("401") ||
normalized.includes("403")
) {
return "Unable to load dataset splits. This dataset may be private or gated. Add a Hugging Face token with access and try again.";
}
if (normalized.includes("not found") || normalized.includes("404")) {
return "Dataset not found. Check the dataset name and try again.";
}
return "Unable to load dataset split options for this dataset.";
}
// ---------------------------------------------------------------------------
// Hook
// ---------------------------------------------------------------------------
@ -101,7 +132,18 @@ export function useHfDatasetSplits(
})
.catch((err) => {
if (!controller.signal.aborted) {
setError(err.message || "Failed to fetch dataset splits");
const rawErrorMessage =
err instanceof Error
? err.message
: typeof err === "string"
? err
: "Failed to fetch dataset splits";
console.warn("[useHfDatasetSplits] Failed to fetch dataset splits", {
datasetName,
message: rawErrorMessage,
error: err,
});
setError(normalizeDatasetSplitsError(rawErrorMessage));
setEntries([]);
}
})