When handling errors, avoid two failure modes: (a) false-success/zero-signal outcomes and (b) silent data loss. Apply these rules consistently:
1) Fail loudly when correctness is impossible
2) Narrow try/catch scope to only the recoverable part
3) Don’t swallow unrelated exceptions
4) When using fallbacks/retries, preserve provenance
Example pattern (warn-and-degrade, but only for non-fatal parsing):
async function seedFromSchema({ yes, configCollector, directory, prompts, fs, path, getSourcePath }) {
if (!yes) return;
try {
const yaml = require('yaml');
const schemaPath = path.join(getSourcePath('core-skills'), 'module.yaml');
const coreSchema = yaml.parse(await fs.readFile(schemaPath, 'utf8')); // narrowed catch target
// core seeding logic lives OUTSIDE the narrow catch scope
const core = (configCollector.collectedConfig.core ||= {});
// ... proceed with seeding; errors here should surface
} catch (err) {
prompts.log.warn(`Core schema unavailable; skipping backfill: ${err.message}`);
// continue install; do not hide failures in later critical steps
}
}
Use this checklist in review: