Skip to content

fix(utils): handle missing or invalid externalRef.yaml - #157

Closed
nios-x wants to merge 1 commit into
fossology:mainfrom
nios-x:fix/js-yaml-named-import
Closed

nios-x wants to merge 1 commit into
fossology:mainfrom
nios-x:fix/js-yaml-named-import

Conversation

@nios-x

@nios-x nios-x commented Nov 2, 2026 •

Copy link
Copy Markdown

Problem

The license and obligation forms load their custom external_ref fields from public/externalRef.yaml. That file is git-ignored and not shipped, so on a fresh clone it doesn't exist. Vite's SPA fallback then answers /externalRef.yaml with index.html and status 200, and js-yaml parses that HTML as a plain string. config.license.fields then throws:

TypeError: Cannot read properties of undefined (reading 'fields')

That happens inside an un-awaited useEffect promise, so it's an unhandled rejection. The forms render without their custom fields and give no hint about why. The same happens with a 404, or with a config that has no license or obligation section.

Changes

  • loadYaml now rejects non-OK HTTP responses and anything that doesn't parse to a YAML mapping, instead of returning whatever the parser produced.
  • Added loadExternalRefFields(entity) in src/utils/loadYaml.js. It builds the externalRef.yaml URL (including VITE_DOMAIN_SUBDIRECTORY), checks that <entity>.fields is a list, and returns [] on failure. On failure it logs a console warning suggesting public/externalRef.example.yaml be copied to public/externalRef.yaml.
  • createLicense, licenseDetailForm, createObligation and obligationDetailForm now call the helper instead of repeating the same fetch block in each file.
  • js-yaml is imported through its named load export. This removes the only npm run lint warning (import/no-named-as-default-member).

With a valid externalRef.yaml, behaviour is unchanged.

How to test

  1. Remove public/externalRef.yaml (if present) and run npm run dev.
  2. Open Create License or Create Obligation.
    • Before: an Uncaught (in promise) TypeError appears in the console.
    • After: the form renders normally and the console shows a warning explaining how to add the config.
  3. Run cp public/externalRef.example.yaml public/externalRef.yaml and reload. The example's custom fields appear on all four forms.

Also checked:

  • npm run lint: 0 problems (was 1 warning).
  • npm run build succeeds.
  • prettier --check passes for the changed lines. The remaining Prettier warnings in licenseDetailForm.jsx, createObligation.jsx and obligationDetailForm.jsx already exist on main.

@nios-x nios-x closed this Nov 2, 2026
@nios-x
nios-x force-pushed the fix/js-yaml-named-import branch from 84563e6 to 3ae3a94 Compare November 2, 2026 21:25
@nios-x nios-x reopened this Nov 2, 2026
@nios-x
nios-x force-pushed the fix/js-yaml-named-import branch 2 times, most recently from 7bf1129 to 625e5d3 Compare November 2, 2026 21:40
@nios-x nios-x changed the title fix(utils): use named load import from js-yaml fix(utils): handle missing or invalid externalRef.yaml Nov 2, 2026
The forms crashed with an unhandled TypeError when public/externalRef.yaml was absent, because the SPA fallback serves index.html, which parses as a string. Validate the response and parsed config, centralise loading in loadExternalRefFields(), and fall back to no custom fields with a console hint. Also use the named js-yaml load import (fixes the only lint warning).

Signed-off-by: nios-x <devnios7@gmail.com>
@nios-x
nios-x force-pushed the fix/js-yaml-named-import branch from 625e5d3 to aabd1a9 Compare November 2, 2026 21:42
@nios-x

nios-x commented Nov 2, 2026

Copy link
Copy Markdown
Author

Superseded by a fresh PR with the same change.

@nios-x nios-x closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant