expect(result.data[0]?.meta?.custom?.error).toBe('Error when parsing some of the logs');
});
it('improve loki escaping error message when query contains escape',()=>{
constresponse: DataQueryResponse={
data:[],
error:{
refId:'A',
message:'parse error at line 1, col 2: invalid char escape',
},
};
constresult=transformBackendResult(
response,
[
{
refId:'A',
expr:'{place="g\\arden"}',
},
],
[]
);
expect(result.error?.message).toBe(
`parse error at line 1, col 2: invalid char escape. Make sure that all special characters are escaped with \\. For more information on escaping of special characters visit LogQL documentation at https://grafana.com/docs/loki/latest/logql/.`
);
});
it('do not change loki escaping error message when query does not contain escape',()=>{
constresponse: DataQueryResponse={
data:[],
error:{
refId:'A',
message:'parse error at line 1, col 2: invalid char escape',
},
};
constresult=transformBackendResult(
response,
[
{
refId:'A',
expr:'{place="garden"}',
},
],
[]
);
expect(result.error?.message).toBe('parse error at line 1, col 2: invalid char escape');
message:`${message}. Make sure that all special characters are escaped with \\. For more information on escaping of special characters visit LogQL documentation at https://grafana.com/docs/loki/latest/logql/.`,
};
}
returnerror;
}
exportfunctiontransformBackendResult(
response: DataQueryResponse,
queries: LokiQuery[],
derivedFieldConfigs: DerivedFieldConfig[]
):DataQueryResponse{
const{data,...rest}=response;
const{data,error,...rest}=response;
// in the typescript type, data is an array of basically anything.
// we do know that they have to be dataframes, so we make a quick check,
@ -124,6 +151,7 @@ export function transformBackendResult(