Skip to content

Add Target::can_emit capability query; registry generator uses it (#137) - #158

Open
petlenz wants to merge 1 commit into
mainfrom
fix-137-can-emit
Open

Add Target::can_emit capability query; registry generator uses it (#137)#158
petlenz wants to merge 1 commit into
mainfrom
fix-137-can-emit

Conversation

@petlenz

@petlenz petlenz commented Aug 2, 2026

Copy link
Copy Markdown
Member

Closes #137. Also resolves #135's symptom (see note).

Target::emit preconditions were discoverable only by catching std::runtime_error. New API:

[[nodiscard]] virtual auto can_emit(ConstitutiveModel const &) const
    -> std::expected<void, std::string>;  // conservative default: success

Each target's up-front scope guards are extracted into one shared rejection function (scope_rejection / rate_scope_rejection / residual_scope_rejection) used by BOTH can_emit (unexpected) and emit (throw) — message text single-sourced, byte-equality pinned by tests. Documented limit: can_emit success ≠ emit success (emit-time validation may still throw); covered by an explicit test.

recipe_registry_gen now queries can_emit and prints SKIPPED (<reason>) with no catch around emit — unexpected exceptions stay crash-loud. Verified: numsim_material traverses all 6 recipes with per-recipe reasons and exits 0 (previously aborted on the first); standalone emits all 6.

Supersedes PR #149 (the interim blanket-catch fix for #135) — recommend closing #149 unmerged; if #149 merges first, this branch's registry-gen hunk conflicts trivially. One semantic difference vs #149: all-recipes-skipped exits 0 here (a query-based skip is not an error) vs #149's exit 3 — happy to flip if you prefer the nonzero signal.

Tests: new CanEmitTest.cpp (9 tests: accept/reject per target, reason==throw-message equality, polymorphic use via make_target, the NaN-default "success ≠ emit success" case). gcc-14 Debug (-Werror): ctest 331/331. Based on current main (86e1862).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant