Initial LinuxCNC WebAssembly workspace snapshot
This commit is contained in:
58
web/worker/error-map.mjs
Normal file
58
web/worker/error-map.mjs
Normal file
@@ -0,0 +1,58 @@
|
||||
export const ERROR_DEFINITIONS = Object.freeze({
|
||||
0: { code: "ok", message_key: "ok", retryable: false, category: "none" },
|
||||
[-1]: { code: "sim_invalid_argument", message_key: "sim.invalid_argument", retryable: false, category: "core" },
|
||||
[-2]: { code: "sim_not_created", message_key: "sim.not_created", retryable: false, category: "core" },
|
||||
[-3]: { code: "sim_buffer_too_small", message_key: "sim.buffer_too_small", retryable: true, category: "core" },
|
||||
[-4]: { code: "sim_invalid_state", message_key: "sim.invalid_state", retryable: false, category: "core" },
|
||||
[-5]: { code: "sim_unsupported", message_key: "sim.unsupported", retryable: false, category: "capability" },
|
||||
[-100]: { code: "protocol_schema", message_key: "protocol.unsupported_schema", retryable: false, category: "protocol" },
|
||||
[-101]: { code: "protocol_sequence", message_key: "protocol.sequence_gap", retryable: true, category: "protocol" },
|
||||
[-102]: { code: "protocol_state", message_key: "protocol.invalid_state", retryable: false, category: "protocol" },
|
||||
[-103]: { code: "protocol_operation_id", message_key: "protocol.operation_id_required", retryable: false, category: "protocol" },
|
||||
[-104]: { code: "protocol_kind", message_key: "protocol.invalid_kind", retryable: false, category: "protocol" },
|
||||
[-105]: { code: "protocol_argument", message_key: "protocol.invalid_argument", retryable: false, category: "protocol" },
|
||||
[-106]: { code: "protocol_tick", message_key: "protocol.tick_regression", retryable: false, category: "protocol" },
|
||||
[-200]: { code: "event_sequence", message_key: "event.sequence_gap", retryable: true, category: "event" },
|
||||
[-201]: { code: "event_tick", message_key: "event.tick_regression", retryable: false, category: "event" },
|
||||
[-202]: { code: "event_argument", message_key: "event.invalid_argument", retryable: false, category: "event" },
|
||||
[-203]: { code: "event_full", message_key: "event.capacity_exceeded", retryable: true, category: "event" },
|
||||
[-204]: { code: "event_buffer", message_key: "event.buffer_too_small", retryable: true, category: "event" },
|
||||
});
|
||||
|
||||
export function mapCoreError(value, context = {}) {
|
||||
const definition = ERROR_DEFINITIONS[value];
|
||||
if (!definition) {
|
||||
return {
|
||||
status: "error",
|
||||
code: "core_unknown_error",
|
||||
message_key: "core.unknown_error",
|
||||
category: "core",
|
||||
retryable: false,
|
||||
original_code: value,
|
||||
operation_id: context.operation_id ?? null,
|
||||
simulation_tick: context.simulation_tick ?? 0,
|
||||
source: context.source ?? null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: value === 0 ? "ok" : "error",
|
||||
...definition,
|
||||
original_code: value,
|
||||
operation_id: context.operation_id ?? null,
|
||||
simulation_tick: context.simulation_tick ?? 0,
|
||||
source: context.source ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export function realExcluded(capability, reason, substitute = null) {
|
||||
return {
|
||||
status: "REAL-EXCLUDED",
|
||||
code: "real_hardware_excluded",
|
||||
message_key: "capability.real_hardware_excluded",
|
||||
category: "capability",
|
||||
capability,
|
||||
reason,
|
||||
substitute,
|
||||
retryable: false,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user