Skip to content

fix(cli): clear error for empty/comment-only scenario/persona/traits YAML - #1600

Open
PratikDhanave (PratikDhanave) wants to merge 1 commit into
microsoft:mainfrom
PratikDhanave:fix/cli-config-loader-null-yaml
Open

PratikDhanave (PratikDhanave) wants to merge 1 commit into
microsoft:mainfrom
PratikDhanave:fix/cli-config-loader-null-yaml

Conversation

@PratikDhanave

@PratikDhanave PratikDhanave (PratikDhanave) commented Nov 1, 2026 •

Copy link
Copy Markdown

Summary

scope run crashed with an opaque TypeError when the scenario, persona, or traits YAML file was empty or comment-only, instead of the clear validation error each loader is written to raise.

In apps/cli/src/config-loader.ts, loadScenario/loadPersona/loadTraits dereference the parsed YAML immediately (data.task, data.personality, …). The yaml parser returns null for an empty or comment-only file, so the dereference threw TypeError: Cannot read properties of null (reading 'task') and the user never saw the intended message. This adds a null/non-object guard in all three loaders that raises each loader's own validation error.

Demos

N/A — the change is a text-only CLI error message (a thrown Error), not a visual Portal/CLI change, so a recording isn't meaningful. Before/after error text:

Before

$ scope run --scenario empty.yaml
TypeError: Cannot read properties of null (reading 'task')

After

$ scope run --scenario empty.yaml
Error: Scenario file empty.yaml must have a "task" string field

Testing

Added apps/cli/src/config-loader.test.ts (empty scenario, comment-only scenario, comment-only persona, valid-scenario sanity check).

  • pnpm exec vitest run apps/cli/src/config-loader.test.ts → 4 passed. The empty/comment cases fail before the fix (TypeError: Cannot read properties of null) and pass after.
  • pnpm exec vitest run apps/cli → 16 files, 164 tests passed (no regressions).

Documentation and compatibility

None. The change only replaces an uncaught TypeError with the already-documented validation error; no API/CLI flag, schema, or behavior change for valid inputs. Backward compatible.

Checklist

  • If Portal features changed, keep CLI capabilities in sync. — N/A (no Portal change)
  • If Portal components changed, update their Storybook stories. — N/A (no Portal change)
  • If database changes require a migration, include up() / down() and keep it CosmosDB-compatible. — N/A (no DB change)
  • If dependencies changed, update the lockfile and regenerate NOTICE / NOTICE-REVIEW.txt with pnpm notice as needed. — N/A (no dependency change)
  • Video showing the behavior before the suggested change — N/A (text-only error; before/after shown above)
  • Video showing the behavior after the suggested change — N/A (text-only error; before/after shown above)

Developed with AI assistance (Claude Code): the crash was located, the guards added, and the tests written and run locally (vitest). I reviewed and verified the change and take responsibility for it.

…s YAML

loadScenario/loadPersona/loadTraits in config-loader.ts dereference the parsed
YAML immediately (data.task, data.personality, ...). The yaml parser returns
null for an empty or comment-only file, so 'scope run' with such a
scenario/persona/traits file crashed with an opaque
'TypeError: Cannot read properties of null (reading "task")' instead of the
clear validation error each loader is written to raise.

Guard for a null/non-object parse result in all three loaders and raise the
loader's own validation message. Add config-loader.test.ts covering the empty
and comment-only cases plus a valid-scenario sanity check.

This branch has not been deployed

No deployments
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