[BUG] buildDefinition drops the whole type when one item fails validation, and --skipValidation cannot get past a broken .mcdev-validations.js

Open
#2,794 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, node.js
Domain
cli, testing

Research direction

Start with lib/Builder.js and compare _buildDefinition with _buildTemplate; then trace checkCustomRules in lib/util/validations.js and its call from lib/util/config.js. Add tests for a failing item beside a successful one, --skipValidation with an unloadable rules file and a throwing validation(), and non-Error thrown values. Done means good items finish and are reported, skip mode continues with warnings, and thrown values have readable messages.

Written by the indexing model from the issue text.

Description

bug c/Generic validationRule
Current Behavior

Two gaps in how custom validation rules (.mcdev-validations.js) are handled, found while reviewing #2752. Both found by reading the code on develop (10.3.1); not yet reproduced with a live run.

1. One failing item stops the whole build of its type

Builder._buildDefinition (lib/Builder.js) builds all items of a type in one Promise.all with a single catch around it. If validation fails for one item (a validation() that throws, or a rule set to error), then:

  • the result list of that type is lost, even for the items that built fine, and
  • mcdev stops waiting for the other items, which may still be writing files in the background. The command then reports a result that does not match what ended up on disk.

_buildTemplate in the same file already catches errors per item and skips only the failing one. #2752's description says build errors are caught per item, but _buildDefinition does not do that yet.

2. --skipValidation cannot get you past a broken .mcdev-validations.js

The option is meant as the way out when validation is in the way. Today:

  • If .mcdev-validations.js exists but cannot be loaded (syntax error, wrong export), checkCustomRules (lib/util/validations.js, called from lib/util/config.js) stops every command before any item is processed, with or without --skipValidation.
  • If the project's validation() function throws for an item, that item is blocked, with or without --skipValidation.
  • Only single rules that fail or throw are downgraded to warnings by the flag.

So a project whose rules file is broken cannot retrieve, deploy or build at all until someone fixes that file.

Minor: error messages when validation() throws something that is not an Error: throw null gives "Cannot read properties of null", throw 'text' gives "undefined" instead of the thrown text.

Expected Behavior
  1. buildDefinition handles each item on its own, like buildTemplate: a failing item is logged and skipped, the other items are built and returned, and mcdev waits for all of them before it reports.
  2. With --skipValidation, a rules file that cannot be loaded and a validation() that throws are logged as warnings and the command continues, the same way the flag already treats failing single rules. Without the flag the current strict behaviour stays.
  3. Any thrown value gives a readable message (String(ex?.message ?? ex)).
Steps To Reproduce
  1. Add .mcdev-validations.js and enable options.validation.buildDefinition in .mcdevrc.json.
  2. Make validation() throw for one specific key only, then run mcdev bd <bu> -m <type>:<goodKey> -m <type>:<badKey> → nothing is reported as built for the type.
  3. Put a syntax error into .mcdev-validations.js, then run mcdev retrieve <bu> -m <type> --skipValidation → the command stops before retrieving.
Version

10.3.1

Additional comments

Tests should cover: one throwing item next to a good item in buildDefinition; --skipValidation with an unloadable rules file; --skipValidation with a throwing validation(); throw null / throw 'text' messages.

Dominant language
JavaScript
Stars
166
Forks
50
Avg merge
11h 4m
Merged PRs (30d)
36

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Accenture/sfmc-devtools

All issues in Accenture/sfmc-devtools

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.