Commit 24bc2b1c by Dominik Prokop Committed by GitHub

TemplateSrv: Do not throw error for an unknown format but use glob as fallback…

TemplateSrv: Do not throw  error for an unknown format but use glob as fallback and warn in the console (#29955)
parent 35a755fe
......@@ -295,6 +295,13 @@ describe('templateSrv', () => {
expect(result).toBe('test');
});
it('should use glob format when unknown format provided', () => {
let result = _templateSrv.formatValue('test', 'nonexistentformat');
expect(result).toBe('test');
result = _templateSrv.formatValue(['test', 'test1'], 'nonexistentformat');
expect(result).toBe('{test,test1}');
});
it('multi value and glob format should render glob string', () => {
const result = _templateSrv.formatValue(['test', 'test2'], 'glob');
expect(result).toBe('{test,test2}');
......
......@@ -137,9 +137,11 @@ export class TemplateSrv implements BaseTemplateSrv {
args = [];
}
const formatItem = formatRegistry.getIfExists(format);
let formatItem = formatRegistry.getIfExists(format);
if (!formatItem) {
throw new Error(`Variable format ${format} not found`);
console.error(`Variable format ${format} not found. Using glob format as fallback.`);
formatItem = formatRegistry.get('glob');
}
const options: FormatOptions = { value, args, text: text ?? value };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment