From 7d105ff8d15647c6378dd089c259453663a77664 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 18 Sep 2025 17:14:48 -0400 Subject: [PATCH] Throw and error, do not just log an error, if provided schema is not readable I think current behavior violates the principle of the least surprise: I ran validation while providing custom schema source, it executed with many warnings and errors reported to the screen. It is only after scrolling far up, I saw that actually my specification was wrong and operation resorted to built-in schema. amend: removed comment "version is ignored when the network cannot be accessed" --- changelog.d/20250918_173356_yarikoptic_enh_crash.md | 4 ++++ src/setup/loadSchema.ts | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 changelog.d/20250918_173356_yarikoptic_enh_crash.md diff --git a/changelog.d/20250918_173356_yarikoptic_enh_crash.md b/changelog.d/20250918_173356_yarikoptic_enh_crash.md new file mode 100644 index 000000000..8c3e18b27 --- /dev/null +++ b/changelog.d/20250918_173356_yarikoptic_enh_crash.md @@ -0,0 +1,4 @@ +### Changed + +- Throw an error if specified schema (e.g. via `--schema` or `BIDS_SCHEMA` env + var) could not be loaded. diff --git a/src/setup/loadSchema.ts b/src/setup/loadSchema.ts index d8b45f56f..8c6f494eb 100644 --- a/src/setup/loadSchema.ts +++ b/src/setup/loadSchema.ts @@ -6,7 +6,6 @@ import { setCustomMetadataFormats } from '../validators/json.ts' /** * Load the schema from the specification * - * version is ignored when the network cannot be accessed */ export async function loadSchema(version?: string): Promise { let schemaUrl = version @@ -31,10 +30,10 @@ export async function loadSchema(version?: string): Promise { objectPathHandler, ) as Schema } catch (error) { - // No network access or other errors + // If a custom schema URL was explicitly provided, fail rather than falling back console.error(error) - console.error( - `Warning, could not load schema from ${schemaUrl}, falling back to internal version`, + throw new Error( + `Failed to load schema from ${schemaUrl}: ${error instanceof Error ? error.message : String(error)}`, ) } }