Address code review: add error logging, fix type cast, improve error messages
Co-authored-by: rfc1437 <774975+rfc1437@users.noreply.github.com>
This commit is contained in:
@@ -859,7 +859,8 @@ export async function replaceAllMacrosAsync(
|
|||||||
if (hasUnknownMacros && pythonMacroRenderer) {
|
if (hasUnknownMacros && pythonMacroRenderer) {
|
||||||
try {
|
try {
|
||||||
pythonScripts = await pythonMacroRenderer.getEnabledMacroScripts();
|
pythonScripts = await pythonMacroRenderer.getEnabledMacroScripts();
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.warn('[PageRenderer] Failed to resolve Python macro scripts:', error instanceof Error ? error.message : String(error));
|
||||||
pythonScripts = [];
|
pythonScripts = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -892,7 +893,7 @@ export async function replaceAllMacrosAsync(
|
|||||||
hook: m.name,
|
hook: m.name,
|
||||||
source: { kind: 'macro', id: pythonScript.id },
|
source: { kind: 'macro', id: pythonScript.id },
|
||||||
},
|
},
|
||||||
params: params as Record<string, unknown>,
|
params: params,
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await pythonMacroRenderer.renderMacro({
|
const result = await pythonMacroRenderer.renderMacro({
|
||||||
@@ -904,7 +905,8 @@ export async function replaceAllMacrosAsync(
|
|||||||
});
|
});
|
||||||
|
|
||||||
rendered.push(result.html);
|
rendered.push(result.html);
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.warn(`[PageRenderer] Python macro '${m.name}' failed:`, error instanceof Error ? error.message : String(error));
|
||||||
rendered.push('');
|
rendered.push('');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -183,8 +183,9 @@ export async function renderMacro(
|
|||||||
if (pythonInfo) {
|
if (pythonInfo) {
|
||||||
return await pythonMacroRendererFn(pythonInfo, macro.params, context);
|
return await pythonMacroRendererFn(pythonInfo, macro.params, context);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (error) {
|
||||||
return `<span class="macro-error" title="Python macro error">${macro.rawText}</span>`;
|
const errorMessage = error instanceof Error ? error.message : 'Python macro error';
|
||||||
|
return `<span class="macro-error" title="${errorMessage}">${macro.rawText}</span>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ describe('Python macro coexistence in renderer registry', () => {
|
|||||||
|
|
||||||
const result = await renderMacro(macro, context);
|
const result = await renderMacro(macro, context);
|
||||||
expect(result).toContain('macro-error');
|
expect(result).toContain('macro-error');
|
||||||
expect(result).toContain('Python macro error');
|
expect(result).toContain('Resolution failed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show unknown macro error when no Python resolver is set', async () => {
|
it('should show unknown macro error when no Python resolver is set', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user