koala73/worldmonitor · error · TypeError
Unknown physical divergence state: ${String(reading.state)}
Error message
Unknown physical divergence state: ${String(reading.state)} What it means
Each composite reading's state must be one of STATES ('ok','insufficient_history','stale_input','missing_input'); any other state string throws this TypeError, since state drives which reasons and weights are valid downstream.
Source
Thrown at shared/physical-divergence-contract.js:140
export function isPhysicalDivergenceStoredCompositeReason(state, reason) {
if (state === 'ok') return reason === '';
return NON_OK_STATE_PRIORITY.includes(state)
&& COMPOSITE_MEMBER_REASONS.includes(reason)
&& reason.endsWith(`:${state}`);
}
export function buildPhysicalStressComposite(readings) {
const values = Array.isArray(readings) ? readings : [];
const byMetal = new Map();
for (const reading of values) {
if (!METAL_ORDER.includes(reading?.metal)) {
throw new TypeError(`Unsupported physical divergence metal: ${String(reading?.metal)}`);
}
if (byMetal.has(reading.metal)) {
throw new TypeError(`Physical divergence composite repeats a metal: ${reading.metal}`);
}
if (!STATES.includes(reading.state)) {
throw new TypeError(`Unknown physical divergence state: ${String(reading.state)}`);
}
byMetal.set(reading.metal, reading);
}
const weights = METAL_ORDER.map((metal) => ({
metal,
weight: PHYSICAL_DIVERGENCE_CONTRACT.metals[metal].weight,
methodologyVersion: METHODOLOGY_VERSION,
}));
for (const metal of METAL_ORDER) {
if (!byMetal.has(metal)) {
return {
state: 'missing_input',
reason: `member_not_ok:${metal}:missing_input`,
index: null,
weights,
methodologyVersion: METHODOLOGY_VERSION,
};
}View on GitHub (pinned to 9361220cc0)
Solutions
- Use only the four contract states: 'ok','insufficient_history','stale_input','missing_input'
- Derive states via contract helpers (e.g. physicalDivergenceStateForFreshnessReason) instead of hand-writing them
- Pre-validate with STATES.includes(reading.state) before the call
- Align producer/consumer contract versions; add genuinely new states to STATES explicitly
Example fix
// before
buildPhysicalStressComposite([{ metal: 'gold', state: 'stale', index: 1 }])
// after
buildPhysicalStressComposite([{ metal: 'gold', state: 'stale_input', index: 1 }]) Defensive patterns
Strategy: type-guard
Validate before calling
import { STATES } from './physical-divergence-contract.js';
function hasValidStates(readings) {
return (Array.isArray(readings) ? readings : []).every((r) => STATES.includes(r?.state));
} Type guard
function isDivergenceState(v) {
return typeof v === 'string' && STATES.includes(v);
} Try / catch
try {
composite = buildPhysicalStressComposite(readings);
} catch (e) {
if (e instanceof TypeError && e.message.startsWith('Unknown physical divergence state')) {
composite = null; // inspect reading.state values
} else throw e;
} Prevention
- Only use 'ok','insufficient_history','stale_input','missing_input'
- Derive states from contract helpers rather than raw upstream statuses
- Share the contract module between producer and consumer
- Add contract conformance tests for state values
When it happens
Trigger: Passing a state not in the contract such as 'stale', 'unknown', 'error', a typo like 'stale_imput', or undefined state on malformed readings.
Common situations: Producers inventing ad-hoc state labels; version drift between a newer producer state and older shared contract; mapping code that transforms upstream statuses incorrectly.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Unknown physical divergence freshness reason: ${String(reaso
- Unsupported physical divergence metal: ${String(reading?.met
- Physical divergence composite repeats a metal: ${reading.met
- Ok physical divergence reading has an invalid index: ${metal
- get-china-decision-signals returned no canonical payload
AI-assisted analysis of koala73/worldmonitor@9361220cc0 (2026-09-01).
Data as JSON: /api/errors/c8f45544988bc502.
Report an issue: GitHub.