mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TemplateSrv: Do not throw error for an unknown format but use glob as fallback and warn in the console (#29955)
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user