warning — Emit formatted warnings and control warning state by identifier.
warning emits non-fatal diagnostic messages and manages warning enable/disable/error states globally or per identifier, following MATLAB-compatible control forms.
Syntax
state = warning()
state = warning(message)
state = warning(message, A...)
state = warning(message_id, message)
state = warning(message_id, message, A...)
state = warning(state)All supported warning forms
state = warning()
state = warning(message)
state = warning(message, A...)
state = warning(message_id, message)
state = warning(message_id, message, A...)
state = warning(state)
state = warning(mode)
state = warning(mode, target)
state = warning("default")
state = warning("default", target)
state = warning("reset")
state = warning("query")
state = warning("query", target)
state = warning("status")
state = warning("backtrace")
state = warning("backtrace", state)
state = warning(mex)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
message | StringScalar | Yes | — | Warning message text or command token. |
message | StringScalar | Yes | — | Warning message template text. |
A | Any | Variadic | — | Formatting values for the warning message template. |
message_id | StringScalar | Yes | "RunMat:warning" | Warning identifier. |
message | StringScalar | Yes | — | Warning message text. |
state | Any | Yes | — | State struct/cell snapshot to restore. |
mode | StringScalar | Yes | — | Mode token ('on','off','once','error','default','reset','query','status','backtrace'). |
mode | StringScalar | Yes | — | Mode token. |
target | StringScalar | Yes | "all" | Identifier/special target for mode updates or queries. |
command | StringScalar | Yes | "backtrace" | Backtrace command token. |
state | StringScalar | Yes | "off" | Backtrace state ('on' or 'off'). |
Returns
| Name | Type | Description |
|---|---|---|
state_or_status | Any | Numeric success sentinel or state/status struct/cell/string result. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:warning | Arguments are invalid for the warning parser branch or command contract. | warning: invalid input arguments |
RunMat:warning | Warning mode is configured to promote warnings to errors. | warning: promoted to error |
How warning works
warning(message)prints the message using the default identifierRunMat:warning.warning(id, fmt, args...)associates the warning with the identifierid, formats the message using MATLAB'ssprintfrules, and honours per-identifier state.warning(MException_obj)reissues an existing exception as a warning.warning(struct)restores warning state previously captured withwarning('query', ...).warning(state, id)changes the mode forid('on','off','once','error', and the aliases'all'or'last'). The call returns a struct describing the prior state so you can restore it later.warning(state, mode)controls diagnostic verbosity modes such as'backtrace'and'verbose', returning a struct snapshot of the previous setting.warning('default', id)resetsid(or'all','backtrace','verbose','last') to the factory default, returning the state that was active before the reset.warning('reset')restores every warning, mode, and once-tracking flag in one call.warning('query', id)returns a struct describing the current mode forid. Passing'all'returns a cell vector of structs covering every configured identifier plus the global default and diagnostic modes.warning('status')prints the global warning table as a formatted summary.- All state-changing forms return struct snapshots; pass them back to
warninglater to reinstate the captured state.
Does RunMat run warning on the GPU?
warning is a control-flow builtin that runs on the host. When formatted arguments include GPU resident arrays (for example via %g specifiers), RunMat gathers the values to host memory before formatting the message so the diagnostic text matches MATLAB expectations.
GPU memory and residency
warning is a control-flow builtin that runs on the host. When formatted arguments include GPU resident arrays (for example via %g specifiers), RunMat gathers the values to host memory before formatting the message so the diagnostic text matches MATLAB expectations.
Examples
Displaying a simple warning
warning("Computation took longer than expected.")Emitting a warning with a custom identifier
warning("runmat:io:deprecatedOption", ...
"Option '%s' is deprecated and will be removed in %s.", ...
"VerboseMode", "1.2")Turning a specific warning off and back on
warning("off", "runmat:io:deprecatedOption");
% ... code that triggers the warning ...
warning("on", "runmat:io:deprecatedOption")Promoting a warning to an error
warning("error", "runmat:solver:illConditioned");
% The next call raises an error instead of printing a warning.
warning("runmat:solver:illConditioned", ...
"Condition number exceeds threshold %.2e.", 1e12)Querying and restoring warning state
state = warning("query", "all"); % capture the current table
warning("off", "all"); % silence all warnings temporarily
warning("Some temporary warning.");
warning(state); % restore original configurationEnabling backtraces for debugging
warning("on", "backtrace"); % warning("backtrace","on") is equivalent
warning("runmat:demo:slowPath", "Inspect the call stack above for context.");
warning("off", "backtrace")Displaying verbose suppression guidance
warning("on", "verbose");
warning("runmat:demo:slowPath", "Inspect the call stack above for context.");
warning("default", "verbose"); % restore the default verbosityUsing warning with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how warning changes the result.
Run a small warning example, explain the result, then change one input and compare the output.
FAQ
Does RunMat keep track of the last warning?⌄
Yes. The last identifier and message are stored internally and will be exposed through the MATLAB-compatible lastwarn builtin.
What does 'once' do?⌄
The first occurrence of the warning is shown, and subsequent uses of the same identifier are suppressed until you change the state.
How do I restore defaults after experimentation?⌄
Call warning('reset') to revert the global default, per-identifier table, diagnostic modes, and once-tracking.
Do state-changing calls return anything useful?⌄
Yes. Forms such as warning('off','id'), warning('on','backtrace'), and warning('default') return struct snapshots describing the state before the change. Store the struct and pass it back to warning later to restore the captured configuration.
What does the 'verbose' mode do?⌄
When enabled (warning('on','verbose')), RunMat prints an additional hint describing how to suppress the warning. Disable it with warning('default','verbose').
What happens when a warning is promoted to 'error'?⌄
The warning text is reused to raise an error with the same identifier, just like MATLAB.
Does warning run on the GPU?⌄
No. Control-flow builtins execute on the host. GPU inputs referenced in formatted messages are gathered automatically before the message is emitted.
Can I provide multiple state structs to warning(state)?⌄
Yes. Pass either a struct or a cell array of structs (as returned by warning('query','all')); RunMat applies them sequentially.
Does warning('on','backtrace') match MATLAB output exactly?⌄
RunMat prints a Rust backtrace for now. Future releases will map this to MATLAB-style stack frames, but the enable/disable semantics match MATLAB.
Is whitespace in identifiers allowed?⌄
Identifiers follow MATLAB rules: they must contain at least one colon and no whitespace. RunMat normalises bare names by prefixing RunMat:.
What if I call warning with unsupported arguments?⌄
RunMat issues a MATLAB-compatible usage error so you can correct the call.
Are repeated calls thread-safe?⌄
Internally the warning table is guarded by a mutex, so concurrent invocations are serialised and remain deterministic.
Related Diagnostics functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how warning is executed, line by line, in Rust.
- View the source for warning in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.