Macros 2.0 expose runtime warn log function
| @@ -297,7 +297,7 @@ export function registerCoreMacros() { | |||
| 297 | '{{roll::6}}', | 297 | '{{roll::6}}', |
| 298 | '{{roll::3d6+4}}', | 298 | '{{roll::3d6+4}}', |
| 299 | ], | 299 | ], |
| 300 | handler: ({ unnamedArgs: [formula] }) => { | 300 | handler: ({ unnamedArgs: [formula], warn }) => { |
| 301 | // If only digits were provided, treat it as `1dX`. | 301 | // If only digits were provided, treat it as `1dX`. |
| 302 | if (/^\d+$/.test(formula)) { | 302 | if (/^\d+$/.test(formula)) { |
| 303 | formula = `1d${formula}`; | 303 | formula = `1d${formula}`; |
| @@ -305,7 +305,7 @@ export function registerCoreMacros() { | |||
| 305 | 305 | ||
| 306 | const isValid = droll.validate(formula); | 306 | const isValid = droll.validate(formula); |
| 307 | if (!isValid) { | 307 | if (!isValid) { |
| 308 | console.debug(`Invalid roll formula: ${formula}`); | 308 | warn(`Invalid roll formula: ${formula}`); |
| 309 | return ''; | 309 | return ''; |
| 310 | } | 310 | } |
| 311 | 311 | ||
| @@ -125,6 +125,8 @@ export const MacroValueType = Object.freeze({ | |||
| 125 | * Use when delayArgResolution is true. By default, preserves the caller's globalOffset so nested | 125 | * Use when delayArgResolution is true. By default, preserves the caller's globalOffset so nested |
| 126 | * macros like {{pick}} maintain deterministic position-based behavior. Pass offsetDelta to add | 126 | * macros like {{pick}} maintain deterministic position-based behavior. Pass offsetDelta to add |
| 127 | * an additional offset for uniqueness (e.g., to differentiate between multiple resolve calls). | 127 | * an additional offset for uniqueness (e.g., to differentiate between multiple resolve calls). |
| 128 | * @property {(message: string, error?: any) => void} warn - Logs a runtime warning with automatic macro call context. | ||
| 129 | * Use this to report issues in how the macro was invoked (e.g., invalid argument values, edge cases). | ||
| 128 | */ | 130 | */ |
| 129 | 131 | ||
| 130 | /** | 132 | /** |
| @@ -375,6 +377,7 @@ class MacroRegistry { | |||
| 375 | resolve: (text, { offsetDelta = 0 } = {}) => MacroEngine.evaluate(text, call.env, { | 377 | resolve: (text, { offsetDelta = 0 } = {}) => MacroEngine.evaluate(text, call.env, { |
| 376 | contextOffset: call.globalOffset + offsetDelta, | 378 | contextOffset: call.globalOffset + offsetDelta, |
| 377 | }), | 379 | }), |
| 380 | warn: (message, error = undefined) => logMacroRuntimeWarning({ message, call, def, error }), | ||
| 378 | }; | 381 | }; |
| 379 | 382 | ||
| 380 | const result = def.handler(executionContext); | 383 | const result = def.handler(executionContext); |