mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Vega] Improve error message in case of invalid $schema URL (#114459)
* 🐛 Catch the schema parser and provide a better error message * 🌐 Add i18n
This commit is contained in:
parent
df971b7dc9
commit
ba8abc4151
2 changed files with 40 additions and 14 deletions
|
@ -81,6 +81,20 @@ describe(`VegaParser.parseAsync`, () => {
|
|||
})
|
||||
)
|
||||
);
|
||||
|
||||
test(`should return a specific error in case of $schema URL not valid`, async () => {
|
||||
const vp = new VegaParser({
|
||||
$schema: 'https://vega.github.io/schema/vega-lite/v4.jsonanythingtobreakthis',
|
||||
mark: 'circle',
|
||||
encoding: { row: { field: 'a' } },
|
||||
});
|
||||
|
||||
await vp.parseAsync();
|
||||
|
||||
expect(vp.error).toBe(
|
||||
'The URL for the JSON "$schema" is incorrect. Correct the URL, then click Update.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe(`VegaParser._setDefaultValue`, () => {
|
||||
|
|
|
@ -553,25 +553,37 @@ The URL is an identifier only. Kibana and your browser will never access this UR
|
|||
* @private
|
||||
*/
|
||||
private parseSchema(spec: VegaSpec) {
|
||||
const schema = schemaParser(spec.$schema);
|
||||
const isVegaLite = schema.library === 'vega-lite';
|
||||
const libVersion = isVegaLite ? vegaLiteVersion : vegaVersion;
|
||||
try {
|
||||
const schema = schemaParser(spec.$schema);
|
||||
const isVegaLite = schema.library === 'vega-lite';
|
||||
const libVersion = isVegaLite ? vegaLiteVersion : vegaVersion;
|
||||
|
||||
if (versionCompare(schema.version, libVersion) > 0) {
|
||||
this._onWarning(
|
||||
i18n.translate('visTypeVega.vegaParser.notValidLibraryVersionForInputSpecWarningMessage', {
|
||||
if (versionCompare(schema.version, libVersion) > 0) {
|
||||
this._onWarning(
|
||||
i18n.translate(
|
||||
'visTypeVega.vegaParser.notValidLibraryVersionForInputSpecWarningMessage',
|
||||
{
|
||||
defaultMessage:
|
||||
'The input spec uses {schemaLibrary} {schemaVersion}, but current version of {schemaLibrary} is {libraryVersion}.',
|
||||
values: {
|
||||
schemaLibrary: schema.library,
|
||||
schemaVersion: schema.version,
|
||||
libraryVersion: libVersion,
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return { isVegaLite, libVersion };
|
||||
} catch (e) {
|
||||
throw Error(
|
||||
i18n.translate('visTypeVega.vegaParser.notValidSchemaForInputSpec', {
|
||||
defaultMessage:
|
||||
'The input spec uses {schemaLibrary} {schemaVersion}, but current version of {schemaLibrary} is {libraryVersion}.',
|
||||
values: {
|
||||
schemaLibrary: schema.library,
|
||||
schemaVersion: schema.version,
|
||||
libraryVersion: libVersion,
|
||||
},
|
||||
'The URL for the JSON "$schema" is incorrect. Correct the URL, then click Update.',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return { isVegaLite, libVersion };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue